Permalink
Browse files

Merge remote branch 'bcui/master'

  • Loading branch information...
2 parents 939b301 + 8b63eeb commit 14de89fe1c2fc3d8cca4bfcd234a6934b7433787 @wonlay wonlay committed Mar 30, 2012
@@ -818,22 +818,44 @@ limit_clause returns [int offset, int count]
}
;
+or_column_name_list returns [JSONArray json]
+@init {
+ $json = new JSONArray();
+}
+ : col=column_name
+ {
+ String colName = $col.text;
+ if (colName != null) {
+ $json.put($col.text);
+ }
+ }
+ (OR col=column_name
+ {
+ colName = $col.text;
+ if (colName != null) {
+ $json.put($col.text);
+ }
+ }
+ )*
+ ;
+
group_by_clause returns [JSONObject json]
- : GROUP BY column_name (TOP top=INTEGER)?
+ : GROUP BY or_column_name_list (TOP top=INTEGER)?
{
$json = new JSONObject();
try {
- JSONArray cols = new JSONArray();
- String col = $column_name.text;
- String[] facetInfo = _facetInfoMap.get(col);
- if (facetInfo != null && (facetInfo[0].equals("range") ||
- facetInfo[0].equals("multi") ||
- facetInfo[0].equals("path"))) {
- throw new FailedPredicateException(input,
- "group_by_clause",
- "Range/multi/path facet, \"" + col + "\", cannot be used in the GROUP BY clause.");
+ JSONArray cols = $or_column_name_list.json;
+ for (int i = 0; i < cols.length(); ++i) {
+ String col = cols.getString(i);
+ String[] facetInfo = _facetInfoMap.get(col);
+ if (facetInfo != null && (facetInfo[0].equals("range") ||
+ facetInfo[0].equals("multi") ||
+ facetInfo[0].equals("path"))) {
+ throw new FailedPredicateException(input,
+ "group_by_clause",
+ "Range/multi/path facet, \"" + col + "\", cannot be used in the GROUP BY clause.");
+ }
}
- cols.put(col);
$json.put("columns", cols);
if (top != null) {
$json.put("top", Integer.parseInt(top.getText()));
@@ -1552,7 +1574,7 @@ null_predicate returns [JSONObject json]
}
;
-value_list returns [Object json]
+non_variable_value_list returns [Object json]
@init {
JSONArray jsonArray = new JSONArray();
}
@@ -1568,6 +1590,14 @@ value_list returns [Object json]
{
$json = jsonArray;
}
+ ;
+
+
+value_list returns [Object json]
+ : non_variable_value_list
+ {
+ $json = $non_variable_value_list.json;
+ }
| VARIABLE
{
$json = $VARIABLE.text;
@@ -1703,7 +1733,7 @@ facet_param_list returns [JSONObject json]
;
facet_param returns [String facet, JSONObject param]
- : LPAR column_name COMMA STRING_LITERAL COMMA facet_param_type COMMA (val=value | valList=value_list) RPAR
+ : LPAR column_name COMMA STRING_LITERAL COMMA facet_param_type COMMA (val=value | valList=non_variable_value_list) RPAR
{
$facet = $column_name.text; // XXX Check error here?
try {
@@ -110,7 +110,11 @@ public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
if (reader instanceof BoboIndexReader){
BoboIndexReader boboReader = (BoboIndexReader)reader;
FacetHandler facetHandler = (FacetHandler)boboReader.getFacetHandler(_name);
- Object obj = facetHandler.getFacetData(boboReader);
+ Object obj = null;
+ if (facetHandler != null)
+ {
+ obj = facetHandler.getFacetData(boboReader);
+ }
if (obj!=null && obj instanceof FacetDataCache){
FacetDataCache facetData = (FacetDataCache)obj;
TermValueList valArray = facetData.valArray;
@@ -159,6 +159,21 @@ public void testGroupBy2() throws Exception
}
@Test
+ public void testGroupByOrColumns() throws Exception
+ {
+ System.out.println("testGroupByOrColumns");
+ System.out.println("==================================================");
+
+ JSONObject json = _compiler.compile(
+ "SELECT category " +
+ "FROM cars " +
+ "GROUP BY color OR category TOP 5"
+ );
+ JSONObject expected = new JSONObject("{\"groupBy\":{\"columns\":[\"color\",\"category\"],\"top\":5},\"meta\":{\"select_list\":[\"category\"]}}");
+ assertTrue(_comp.isEquals(json, expected));
+ }
+
+ @Test
public void testEqualPredInteger() throws Exception
{
System.out.println("testEqualPredInteger");
@@ -736,6 +736,34 @@ public void testBadGroupBy() throws Exception
}
}
+ @Test
+ public void testBadGroupBy2() throws Exception
+ {
+ System.out.println("testBadGroupBy2");
+ System.out.println("==================================================");
+
+ boolean caughtException = false;
+ try
+ {
+ JSONObject json = _compiler.compile(
+ "select category, tags \n" +
+ "from cars \n" +
+ "group by color OR year \n" +
+ "order by color \n"
+ );
+ }
+ catch (RecognitionException err)
+ {
+ assertEquals("[line:4, col:0] Range/multi/path facet, \"year\", cannot be used in the GROUP BY clause. (token=order)",
+ _compiler.getErrorMessage(err));
+ caughtException = true;
+ }
+ finally
+ {
+ assertTrue(caughtException);
+ }
+ }
+
// @Test
// public void testConflictSelections() throws Exception
// {

0 comments on commit 14de89f

Please sign in to comment.