Skip to content

Commit

Permalink
Merged from fastjson
Browse files Browse the repository at this point in the history
  • Loading branch information
wonlay committed Oct 9, 2012
2 parents 7e66e85 + 24423de commit 09bab78
Show file tree
Hide file tree
Showing 36 changed files with 1,402 additions and 253 deletions.
23 changes: 0 additions & 23 deletions sensei-core/.project

This file was deleted.

6 changes: 6 additions & 0 deletions sensei-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@
<version>20080701</version>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.23</version>
</dependency>

<dependency>
<groupId>com.linkedin</groupId>
<artifactId>norbert_2.8.1</artifactId>
Expand Down
294 changes: 148 additions & 146 deletions sensei-core/src/main/antlr3/com/senseidb/bql/parsers/BQL.g

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.senseidb.search.req.SenseiJSONQuery;
import com.senseidb.search.req.SenseiQuery;
import com.senseidb.search.req.SenseiRequest;
import com.senseidb.util.JSONUtil.FastJSONArray;
import com.senseidb.util.JSONUtil.FastJSONObject;

public class BrowseRequestBuilder {
private SenseiRequest _req;
Expand Down Expand Up @@ -70,7 +72,7 @@ public void setCount(int count){
}

public void setQuery(String qString){
JSONObject qObj = new JSONObject();
JSONObject qObj = new FastJSONObject();
if (qString!=null){
try {
qObj.put("query", qString);
Expand Down
21 changes: 12 additions & 9 deletions sensei-core/src/main/java/com/senseidb/conf/SchemaConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.senseidb.util.JSONUtil.FastJSONArray;
import com.senseidb.util.JSONUtil.FastJSONObject;

public class SchemaConverter
{
private static Logger logger = Logger.getLogger(SchemaConverter.class);

static public JSONObject convert(Document schemaDoc)
throws ConfigurationException, JSONException
{
JSONObject jsonObj = new JSONObject();
JSONObject tableObj = new JSONObject();
JSONObject jsonObj = new FastJSONObject();
JSONObject tableObj = new FastJSONObject();
jsonObj.put("table", tableObj);

NodeList tables = schemaDoc.getElementsByTagName("table");
Expand Down Expand Up @@ -54,15 +57,15 @@ static public JSONObject convert(Document schemaDoc)
tableObj.put("compress-src-data", true);

NodeList columns = tableElem.getElementsByTagName("column");
JSONArray columnArray = new JSONArray();
JSONArray columnArray = new FastJSONArray();
tableObj.put("columns", columnArray);

for (int i = 0; i < columns.getLength(); ++i)
{
try
{
Element column = (Element) columns.item(i);
JSONObject columnObj = new JSONObject();
JSONObject columnObj = new FastJSONObject();
columnArray.put(columnObj);

String n = column.getAttribute("name");
Expand Down Expand Up @@ -119,23 +122,23 @@ static public JSONObject convert(Document schemaDoc)


NodeList facets = schemaDoc.getElementsByTagName("facet");
JSONArray facetArray = new JSONArray();
JSONArray facetArray = new FastJSONArray();
jsonObj.put("facets", facetArray);

for (int i = 0; i < facets.getLength(); ++i)
{
try
{
Element facet = (Element) facets.item(i);
JSONObject facetObj = new JSONObject();
JSONObject facetObj = new FastJSONObject();
facetArray.put(facetObj);

facetObj.put("name", facet.getAttribute("name"));
facetObj.put("type", facet.getAttribute("type"));
String depends = facet.getAttribute("depends");
if (depends!=null){
String[] dependsList = depends.split(",");
JSONArray dependsArr = new JSONArray();
JSONArray dependsArr = new FastJSONArray();
for (String dependName : dependsList)
{
if (dependName != null)
Expand All @@ -158,13 +161,13 @@ static public JSONObject convert(Document schemaDoc)

NodeList paramList = facet.getElementsByTagName("param");
if (paramList!=null){
JSONArray params = new JSONArray();
JSONArray params = new FastJSONArray();
facetObj.put("params", params);
for (int j = 0; j < paramList.getLength(); ++j) {
Element param = (Element) paramList.item(j);
String paramName = param.getAttribute("name");
String paramValue = param.getAttribute("value");
JSONObject paramObj = new JSONObject();
JSONObject paramObj = new FastJSONObject();
paramObj.put("name", paramName);
paramObj.put("value", paramValue);
params.put(paramObj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
import com.senseidb.util.HDFSIndexCopier;
import com.senseidb.util.NetUtil;
import com.senseidb.util.SenseiUncaughtExceptionHandler;
import com.senseidb.util.JSONUtil.FastJSONArray;
import com.senseidb.util.JSONUtil.FastJSONObject;

public class SenseiServerBuilder implements SenseiConfParams{

Expand Down Expand Up @@ -235,7 +237,7 @@ public static JSONObject loadSchema(File confDir) throws Exception{
InputStream is = new FileInputStream(jsonSchema);
String json = IOUtils.toString( is );
is.close();
return new JSONObject(json);
return new FastJSONObject(json);
}
else{
File xmlSchema = new File(confDir,SCHEMA_FILE_XML);
Expand All @@ -256,7 +258,7 @@ public static JSONObject loadSchema(Resource confDir) throws Exception
{
if (confDir.createRelative(SCHEMA_FILE_JSON).exists()){
String json = IOUtils.toString(confDir.createRelative(SCHEMA_FILE_JSON).getInputStream());
return new JSONObject(json);
return new FastJSONObject(json);
}
else{
if (confDir.createRelative(SCHEMA_FILE_XML).exists()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.senseidb.conf.SenseiServerBuilder;
import com.senseidb.indexing.DefaultJsonSchemaInterpreter;
import com.senseidb.search.plugin.PluggableSearchEngineManager;
import com.senseidb.util.JSONUtil.FastJSONArray;
import com.senseidb.util.JSONUtil.FastJSONObject;

public class SchemaIndexingExample{

Expand All @@ -46,7 +48,7 @@ public Set<String> getFieldNames() {
String line = br.readLine();
if (line==null) break;

JSONObject obj = new JSONObject(line);
JSONObject obj = new FastJSONObject(line);
ZoieIndexable indexable = defaultInterpreter.convertAndInterpret(obj);
IndexingReq[] idxReqs = indexable.buildIndexingReqs();
for (IndexingReq req : idxReqs){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import com.senseidb.indexing.DataSourceFilter;
import com.senseidb.indexing.DataSourceFilterable;
import com.senseidb.util.JSONUtil.FastJSONArray;
import com.senseidb.util.JSONUtil.FastJSONObject;

public class LinedJsonFileDataProvider extends LinedFileDataProvider<JSONObject> implements DataSourceFilterable<String> {

Expand Down Expand Up @@ -38,7 +40,7 @@ protected JSONObject convertLine(String line) throws IOException {

// Try to create directly.
try {
return new JSONObject(line);
return new FastJSONObject(line);
} catch (JSONException e) {
throw new IOException(e.getMessage(),e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import com.senseidb.plugin.SenseiPluginRegistry;
import com.senseidb.search.node.SenseiIndexingManager;
import com.senseidb.search.plugin.PluggableSearchEngineManager;
import com.senseidb.util.JSONUtil.FastJSONArray;
import com.senseidb.util.JSONUtil.FastJSONObject;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Meter;
import com.yammer.metrics.core.MetricName;
Expand Down Expand Up @@ -293,7 +295,7 @@ else if (type != null)
return null;
}

JSONObject newEvent = new JSONObject(new String(data, "UTF-8"));
JSONObject newEvent = new FastJSONObject(new String(data, "UTF-8"));
Iterator<String> keys = event.keys();
while(keys.hasNext())
{
Expand Down Expand Up @@ -364,7 +366,7 @@ public void consume(Collection<proj.zoie.api.DataConsumer.DataEvent<JSONObject>>
{
if (partDataSet.size() == 0)
{
JSONObject markerObj = new JSONObject();
JSONObject markerObj = new FastJSONObject();
//markerObj.put(_senseiSchema.getSkipField(), "true");
markerObj.put(SenseiSchema.EVENT_TYPE_FIELD, SenseiSchema.EVENT_TYPE_SKIP);
markerObj.put(_uidField, 0L); // Add a dummy uid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import org.json.JSONObject;

import com.senseidb.util.JSONUtil.FastJSONArray;
import com.senseidb.util.JSONUtil.FastJSONObject;

public class StringJsonFilter extends DataSourceFilter<String> {

private JsonFilter _innerFilter;
Expand All @@ -20,7 +23,7 @@ public JsonFilter getInnerFilter(){

@Override
protected JSONObject doFilter(String data) throws Exception {
JSONObject json = new JSONObject(data);
JSONObject json = new FastJSONObject(data);
if (_innerFilter!=null){
json = _innerFilter.doFilter(json);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.senseidb.search.node.SenseiQueryBuilder;
import com.senseidb.search.node.SenseiQueryBuilderFactory;
import com.senseidb.search.req.SenseiQuery;
import com.senseidb.util.JSONUtil.FastJSONArray;
import com.senseidb.util.JSONUtil.FastJSONObject;

public abstract class AbstractJsonQueryBuilderFactory implements
SenseiQueryBuilderFactory {
Expand All @@ -15,7 +17,7 @@ public SenseiQueryBuilder getQueryBuilder(SenseiQuery query)
JSONObject jsonQuery=null;
if (query!=null){
byte[] bytes = query.toBytes();
jsonQuery = new JSONObject(new String(bytes,SenseiQuery.utf8Charset));
jsonQuery = new FastJSONObject(new String(bytes,SenseiQuery.utf8Charset));
}
return buildQueryBuilder(jsonQuery);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.senseidb.search.node.SenseiQueryBuilder;
import com.senseidb.search.query.QueryConstructor;
import com.senseidb.search.query.filters.FilterConstructor;
import com.senseidb.util.JSONUtil.FastJSONArray;
import com.senseidb.util.JSONUtil.FastJSONObject;

public class DefaultJsonQueryBuilderFactory extends
AbstractJsonQueryBuilderFactory {
Expand All @@ -36,8 +38,8 @@ else if (obj instanceof JSONObject)
query = (JSONObject)obj;
else if (obj instanceof String)
{
query = new JSONObject();
JSONObject tmp = new JSONObject();
query = new FastJSONObject();
JSONObject tmp = new FastJSONObject();
try
{
tmp.put("query", (String)obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.json.JSONObject;

import com.senseidb.conf.SenseiSchema;
import com.senseidb.util.JSONUtil.FastJSONArray;
import com.senseidb.util.JSONUtil.FastJSONObject;

import proj.zoie.store.ZoieStoreSerializer;

Expand Down Expand Up @@ -41,7 +43,7 @@ public byte[] toBytes(JSONObject data) {
@Override
public JSONObject fromBytes(byte[] data) {
try {
return new JSONObject(new String(data,UTF8));
return new FastJSONObject(new String(data,UTF8));
} catch (JSONException e) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import org.json.JSONException;
import org.json.JSONObject;

import com.senseidb.util.JSONUtil.FastJSONArray;
import com.senseidb.util.JSONUtil.FastJSONObject;


public class ConstExpQueryConstructor extends QueryConstructor
{
Expand Down Expand Up @@ -260,10 +263,10 @@ else if(!(lvalue instanceof JSONArray) && !(rvalue instanceof JSONArray))


public static void main(String args[]) throws JSONException{
JSONObject json = new JSONObject();
JSONObject func = new JSONObject();
JSONObject json = new FastJSONObject();
JSONObject func = new FastJSONObject();
func.put("function", "length");
func.put("params", new JSONArray().put(new JSONArray()));
func.put("params", new FastJSONArray().put(new FastJSONArray()));
json.put("lvalue", func);
json.put("operator", "==");
json.put("rvalue", 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.json.JSONObject;

import com.senseidb.search.query.filters.FilterConstructor;
import com.senseidb.util.JSONUtil.FastJSONArray;
import com.senseidb.util.JSONUtil.FastJSONObject;


public class PathQueryConstructor extends QueryConstructor
Expand All @@ -25,7 +27,7 @@ protected Query doConstructQuery(JSONObject jsonQuery) throws JSONException
Filter filter = null;
try
{
JSONObject newJson = new JSONObject();
JSONObject newJson = new FastJSONObject();
newJson.put(QUERY_TYPE, jsonQuery);
filter = FilterConstructor.constructFilter(newJson, null/* QueryParser is not used by this filter */);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.json.JSONObject;

import com.senseidb.search.query.filters.FilterConstructor;
import com.senseidb.util.JSONUtil.FastJSONArray;
import com.senseidb.util.JSONUtil.FastJSONObject;


public class RangeQueryConstructor extends QueryConstructor
Expand All @@ -30,7 +32,7 @@ protected Query doConstructQuery(JSONObject jsonQuery) throws JSONException
Filter filter = null;
try
{
JSONObject newJson = new JSONObject();
JSONObject newJson = new FastJSONObject();
newJson.put(QUERY_TYPE, jsonQuery);
filter = FilterConstructor.constructFilter(newJson, null/* QueryParser is not used by this filter */);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.json.JSONObject;

import com.senseidb.search.query.filters.FilterConstructor;
import com.senseidb.util.JSONUtil.FastJSONArray;
import com.senseidb.util.JSONUtil.FastJSONObject;


public class UIDQueryConstructor extends QueryConstructor
Expand All @@ -18,7 +20,7 @@ public class UIDQueryConstructor extends QueryConstructor
@Override
protected Query doConstructQuery(JSONObject jsonQuery) throws JSONException
{
JSONObject filterJson = new JSONObject();
JSONObject filterJson = new FastJSONObject();
filterJson.put(QUERY_TYPE, jsonQuery);

Filter filter = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.json.JSONObject;

import com.senseidb.search.query.QueryConstructor;
import com.senseidb.util.JSONUtil.FastJSONArray;
import com.senseidb.util.JSONUtil.FastJSONObject;

public class ConstExpFilterConstructor extends FilterConstructor
{
Expand All @@ -14,7 +16,7 @@ public class ConstExpFilterConstructor extends FilterConstructor
@Override
protected Filter doConstructFilter(Object json) throws Exception
{
Query q = QueryConstructor.constructQuery(new JSONObject().put(FILTER_TYPE, (JSONObject)json), null);
Query q = QueryConstructor.constructQuery(new FastJSONObject().put(FILTER_TYPE, (JSONObject)json), null);
if (q == null)
return null;
return new QueryWrapperFilter(q);
Expand Down
Loading

0 comments on commit 09bab78

Please sign in to comment.