Repository: incubator-lens
Updated Branches:
  refs/heads/master 16be6fba8 -> 30c67bc59


LENS-508 : Implement error codes and response for 'fields cannot be queried 
together' error (Himanshu Gahlaut via amareshwari)


Project: http://git-wip-us.apache.org/repos/asf/incubator-lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-lens/commit/30c67bc5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-lens/tree/30c67bc5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-lens/diff/30c67bc5

Branch: refs/heads/master
Commit: 30c67bc59007aa7347c8c56e2a390045a267dee4
Parents: 16be6fb
Author: Himanshu Gahlaut <[email protected]>
Authored: Thu May 14 12:41:09 2015 +0530
Committer: Amareshwari Sriramadasu <[email protected]>
Committed: Thu May 14 12:41:09 2015 +0530

----------------------------------------------------------------------
 lens-api/src/main/resources/lens-errors.conf    |  15 +-
 .../ColUnAvailableInTimeRangeException.java     |   2 +-
 .../lens/cube/error/ConflictingFields.java      |  63 +++++++
 .../FieldsCannotBeQueriedTogetherException.java |  58 +++++++
 .../lens/cube/error/LensCubeErrorCode.java      |   5 +-
 .../apache/lens/cube/parse/FieldValidator.java  |  29 ++--
 .../FieldsCannotBeQueriedTogetherTest.java      | 171 +++++++++++++++++++
 .../lens/cube/parse/TestBaseCubeQueries.java    |  51 ------
 8 files changed, 323 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/30c67bc5/lens-api/src/main/resources/lens-errors.conf
----------------------------------------------------------------------
diff --git a/lens-api/src/main/resources/lens-errors.conf 
b/lens-api/src/main/resources/lens-errors.conf
index 33e68a5..26bda1f 100644
--- a/lens-api/src/main/resources/lens-errors.conf
+++ b/lens-api/src/main/resources/lens-errors.conf
@@ -76,10 +76,17 @@ lensCubeErrors = [
  }
 
  {
-    errorCode = 3002
-    httpStatusCode = ${BAD_REQUEST}
-    errorMsg = "%s can only be queried %s. Please adjust the selected time 
range accordingly."
-    payloadClass = org.apache.lens.cube.error.ColUnAvailableInTimeRange
+   errorCode = 3002
+   httpStatusCode = ${BAD_REQUEST}
+   errorMsg = "%s can only be queried %s. Please adjust the selected time 
range accordingly."
+   payloadClass = org.apache.lens.cube.error.ColUnAvailableInTimeRange
+ }
+
+ {
+   errorCode = 3003
+   httpStatusCode = ${BAD_REQUEST}
+   errorMsg = "%s. Please remove conflicting fields and try again."
+   payloadClass = org.apache.lens.cube.error.ConflictingFields
  }
 
 ]

http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/30c67bc5/lens-cube/src/main/java/org/apache/lens/cube/error/ColUnAvailableInTimeRangeException.java
----------------------------------------------------------------------
diff --git 
a/lens-cube/src/main/java/org/apache/lens/cube/error/ColUnAvailableInTimeRangeException.java
 
b/lens-cube/src/main/java/org/apache/lens/cube/error/ColUnAvailableInTimeRangeException.java
index 9419c78..99a78f6 100644
--- 
a/lens-cube/src/main/java/org/apache/lens/cube/error/ColUnAvailableInTimeRangeException.java
+++ 
b/lens-cube/src/main/java/org/apache/lens/cube/error/ColUnAvailableInTimeRangeException.java
@@ -53,7 +53,7 @@ public class ColUnAvailableInTimeRangeException extends 
LensException {
       final String stackTrace) {
 
     return LensErrorTO.composedOf(COLUMN_UNAVAILABLE_IN_TIME_RANGE.getValue(), 
errorMsg, stackTrace,
-        colUnAvailableInTimeRange, null);
+        colUnAvailableInTimeRange);
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/30c67bc5/lens-cube/src/main/java/org/apache/lens/cube/error/ConflictingFields.java
----------------------------------------------------------------------
diff --git 
a/lens-cube/src/main/java/org/apache/lens/cube/error/ConflictingFields.java 
b/lens-cube/src/main/java/org/apache/lens/cube/error/ConflictingFields.java
new file mode 100644
index 0000000..5b94e3b
--- /dev/null
+++ b/lens-cube/src/main/java/org/apache/lens/cube/error/ConflictingFields.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.lens.cube.error;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+
+import java.util.*;
+
+import javax.xml.bind.annotation.*;
+
+import org.apache.commons.lang.StringUtils;
+
+import lombok.*;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+@NoArgsConstructor(access = AccessLevel.PACKAGE)
+@EqualsAndHashCode
+@ToString
+public class ConflictingFields {
+
+  private static final String SEP = ", ";
+
+  @XmlElementWrapper(name = "conflictingFields")
+  @XmlElement(name = "field")
+  private SortedSet<String> fields;
+
+  public ConflictingFields(@NonNull final SortedSet<String> fields) {
+
+    checkArgument(!fields.isEmpty(), "We should atleast have one conflicting 
field to create a valid instance.");
+    for (String field : fields) {
+      checkState(field != null, "Conflicting fields must not contain null. 
Conflicting fields: %s", fields);
+    }
+    this.fields = fields;
+  }
+
+  public String getConflictingFieldsString() {
+    String conflictingFieldsStrJoined = StringUtils.join(fields, SEP);
+
+    if (fields.size() == 1) {
+      return conflictingFieldsStrJoined + " cannot be queried";
+    } else {
+      return conflictingFieldsStrJoined + " cannot be queried together";
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/30c67bc5/lens-cube/src/main/java/org/apache/lens/cube/error/FieldsCannotBeQueriedTogetherException.java
----------------------------------------------------------------------
diff --git 
a/lens-cube/src/main/java/org/apache/lens/cube/error/FieldsCannotBeQueriedTogetherException.java
 
b/lens-cube/src/main/java/org/apache/lens/cube/error/FieldsCannotBeQueriedTogetherException.java
new file mode 100644
index 0000000..f246246
--- /dev/null
+++ 
b/lens-cube/src/main/java/org/apache/lens/cube/error/FieldsCannotBeQueriedTogetherException.java
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.lens.cube.error;
+
+import static 
org.apache.lens.cube.error.LensCubeErrorCode.FIELDS_CANNOT_BE_QUERIED_TOGETHER;
+
+import org.apache.lens.api.error.ErrorCollection;
+import org.apache.lens.api.error.LensError;
+import org.apache.lens.api.response.LensErrorTO;
+import org.apache.lens.server.api.error.LensException;
+
+import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+import lombok.ToString;
+
+@EqualsAndHashCode(callSuper = true)
+@ToString
+public class FieldsCannotBeQueriedTogetherException extends LensException {
+
+  private final ConflictingFields conflictingFields;
+
+  public FieldsCannotBeQueriedTogetherException(@NonNull final 
ConflictingFields conflictingFields) {
+
+    super(FIELDS_CANNOT_BE_QUERIED_TOGETHER.getValue());
+    this.conflictingFields = conflictingFields;
+  }
+
+  @Override
+  public String getFormattedErrorMsg(LensError lensError) {
+
+    final String conflictingFieldsStr = 
conflictingFields.getConflictingFieldsString();
+    return lensError.getFormattedErrorMsg(conflictingFieldsStr);
+  }
+
+  @Override
+  protected LensErrorTO buildLensErrorTO(final ErrorCollection 
errorCollection, final String errorMsg,
+      final String stackTrace) {
+
+    return 
LensErrorTO.composedOf(FIELDS_CANNOT_BE_QUERIED_TOGETHER.getValue(), errorMsg, 
stackTrace,
+        conflictingFields);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/30c67bc5/lens-cube/src/main/java/org/apache/lens/cube/error/LensCubeErrorCode.java
----------------------------------------------------------------------
diff --git 
a/lens-cube/src/main/java/org/apache/lens/cube/error/LensCubeErrorCode.java 
b/lens-cube/src/main/java/org/apache/lens/cube/error/LensCubeErrorCode.java
index c635a7e..0006b22 100644
--- a/lens-cube/src/main/java/org/apache/lens/cube/error/LensCubeErrorCode.java
+++ b/lens-cube/src/main/java/org/apache/lens/cube/error/LensCubeErrorCode.java
@@ -21,13 +21,14 @@ package org.apache.lens.cube.error;
 public enum LensCubeErrorCode {
 
   SYNTAX_ERROR(3001),
-  COLUMN_UNAVAILABLE_IN_TIME_RANGE(3002);
+  COLUMN_UNAVAILABLE_IN_TIME_RANGE(3002),
+  FIELDS_CANNOT_BE_QUERIED_TOGETHER(3003);
 
   public int getValue() {
     return this.errorCode;
   }
 
-  private LensCubeErrorCode(final int code) {
+  LensCubeErrorCode(final int code) {
     this.errorCode = code;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/30c67bc5/lens-cube/src/main/java/org/apache/lens/cube/parse/FieldValidator.java
----------------------------------------------------------------------
diff --git 
a/lens-cube/src/main/java/org/apache/lens/cube/parse/FieldValidator.java 
b/lens-cube/src/main/java/org/apache/lens/cube/parse/FieldValidator.java
index ffe6ebd..fd8568f 100644
--- a/lens-cube/src/main/java/org/apache/lens/cube/parse/FieldValidator.java
+++ b/lens-cube/src/main/java/org/apache/lens/cube/parse/FieldValidator.java
@@ -18,16 +18,14 @@
  */
 package org.apache.lens.cube.parse;
 
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 
+import org.apache.lens.cube.error.ConflictingFields;
+import org.apache.lens.cube.error.FieldsCannotBeQueriedTogetherException;
 import org.apache.lens.cube.metadata.CubeInterface;
 import org.apache.lens.cube.metadata.DerivedCube;
 import org.apache.lens.cube.metadata.ReferencedDimAtrribute;
 
-import org.apache.hadoop.hive.ql.ErrorMsg;
 import org.apache.hadoop.hive.ql.metadata.HiveException;
 import org.apache.hadoop.hive.ql.parse.ASTNode;
 import org.apache.hadoop.hive.ql.parse.HiveParser;
@@ -39,11 +37,11 @@ import org.apache.hadoop.hive.ql.parse.SemanticException;
 public class FieldValidator implements ContextRewriter {
 
   @Override
-  public void rewriteContext(CubeQueryContext cubeql) throws SemanticException 
{
+  public void rewriteContext(CubeQueryContext cubeql) throws 
FieldsCannotBeQueriedTogetherException, SemanticException {
     validateFields(cubeql);
   }
 
-  public void validateFields(CubeQueryContext cubeql) throws SemanticException 
{
+  public void validateFields(CubeQueryContext cubeql) throws 
FieldsCannotBeQueriedTogetherException, SemanticException {
     CubeInterface cube = cubeql.getCube();
     if (cube == null) {
       return;
@@ -82,17 +80,24 @@ public class FieldValidator implements ContextRewriter {
         }
       }
 
+      final SortedSet<String> conflictingFields = new TreeSet<String>();
+
       if (!derivedCubeFound && !nonQueryableFields.isEmpty()) {
-        throw new SemanticException(ErrorMsg.FIELDS_NOT_QUERYABLE, 
nonQueryableFields.toString());
+        conflictingFields.addAll(nonQueryableFields);
+        throw new FieldsCannotBeQueriedTogetherException(new 
ConflictingFields(conflictingFields));
       }
 
       if (!queriedMsrs.isEmpty()) {
         // Add appropriate message to know which fields are not queryable 
together
         if (!nonQueryableFields.isEmpty()) {
-          throw new SemanticException(ErrorMsg.FIELDS_NOT_QUERYABLE, 
nonQueryableFields.toString() + " and "
-            + queriedMsrs.toString());
+
+          conflictingFields.addAll(nonQueryableFields);
+          conflictingFields.addAll(queriedMsrs);
+          throw new FieldsCannotBeQueriedTogetherException(new 
ConflictingFields(conflictingFields));
         } else {
-          throw new SemanticException(ErrorMsg.FIELDS_NOT_QUERYABLE, 
queriedMsrs.toString());
+
+          conflictingFields.addAll(queriedMsrs);
+          throw new FieldsCannotBeQueriedTogetherException(new 
ConflictingFields(conflictingFields));
         }
       }
     }
@@ -147,7 +152,5 @@ public class FieldValidator implements ContextRewriter {
         }
       }
     });
-
   }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/30c67bc5/lens-cube/src/test/java/org/apache/lens/cube/parse/FieldsCannotBeQueriedTogetherTest.java
----------------------------------------------------------------------
diff --git 
a/lens-cube/src/test/java/org/apache/lens/cube/parse/FieldsCannotBeQueriedTogetherTest.java
 
b/lens-cube/src/test/java/org/apache/lens/cube/parse/FieldsCannotBeQueriedTogetherTest.java
new file mode 100644
index 0000000..1e0dbf8
--- /dev/null
+++ 
b/lens-cube/src/test/java/org/apache/lens/cube/parse/FieldsCannotBeQueriedTogetherTest.java
@@ -0,0 +1,171 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.lens.cube.parse;
+
+import static org.apache.lens.cube.parse.CubeTestSetup.TWO_DAYS_RANGE;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.fail;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.apache.lens.cube.error.ConflictingFields;
+import org.apache.lens.cube.error.FieldsCannotBeQueriedTogetherException;
+import org.apache.lens.server.api.error.LensException;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.ql.parse.ParseException;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class FieldsCannotBeQueriedTogetherTest extends TestQueryRewrite {
+
+  private Configuration conf = new Configuration();
+
+  @BeforeClass
+  public void beforeClassFieldsCannotBeQueriedTogetherTest() {
+    conf.setBoolean(CubeQueryConfUtil.ENABLE_SELECT_TO_GROUPBY, true);
+  }
+
+  @Test
+  public void testQueryWithDimensionAndMeasure() throws SemanticException, 
ParseException, LensException {
+
+    /* If all the queried dimensions are present in a derived cube, and one of 
the queried measure is not present in
+    the same derived cube, then query shall be disallowed.
+
+    dim2 and msr1 are not present in the same derived cube, hence query shall 
be disallowed with appropriate
+    exception. */
+
+    testFieldsCannotBeQueriedTogetherError("select dim2, SUM(msr1) from 
basecube where " + TWO_DAYS_RANGE,
+        Arrays.asList("dim2", "msr1"));
+  }
+
+  @Test
+  public void testQueryWithChainReferencedDimensionAttributeAndMeasure() 
throws SemanticException, ParseException,
+      LensException {
+
+    /* In this query a dimension attribute referenced through join chain name 
is used in select. If the
+    source column for such a dimension attribute and the  queried measure are 
not present in the same derived cube,
+    then query shall be disallowed.
+
+    cityState.name is a dimension attribute used in select statement and 
referenced through join chain name citystate.
+    It is queryable through chain source column cityid. cityid and msr1 are 
not present in the same derived cube, hence
+    query shall be disallowed with appropriate exception. */
+
+    testFieldsCannotBeQueriedTogetherError("select citystate.name, SUM(msr1) 
from basecube where " + TWO_DAYS_RANGE,
+        Arrays.asList("citystate.name", "msr1"));
+  }
+
+  @Test
+  public void testQueryWithMeasureAndChainReferencedDimAttributeInFilter() 
throws SemanticException, ParseException,
+      LensException {
+
+    /* In this query a dimension attribute referenced through join chain name 
is used in filter. If the
+    source column for such a dimension attribute and the  queried measure are 
not present in the same derived cube,
+    then query shall be disallowed.
+
+    cityState.name is a dimension attribute used in where clause(filter) and 
referenced through join chain name. It is
+    queryable through chain source column cityid. cityid and msr1 are not 
present in the same derived cube, hence query
+    shall be disallowed with appropriate exception. */
+
+    testFieldsCannotBeQueriedTogetherError("select SUM(msr1) from basecube 
where cityState.name = 'foo' and "
+            + TWO_DAYS_RANGE, Arrays.asList("citystate.name", "msr1"));
+  }
+
+  @Test
+  public void testQueryWithOnlyMeasure() throws ParseException, 
SemanticException, LensException {
+
+    /* A query which contains only measure should pass, if the measure is 
present in some derived cube.
+    msr1 is present in one of the derived cubes, hence query shall pass 
without any exception. */
+
+    rewrite("select SUM(msr1) from basecube where " + TWO_DAYS_RANGE, conf);
+  }
+
+  @Test
+  public void 
testQueryWithMeasureAndChainReferencedDimAttributeInCaseStatement() throws 
ParseException,
+      SemanticException, LensException {
+
+    /* In this query a dimension attribute referenced through join chain name 
is used in case statement.
+    A query which contains such a dim attribute and a measure is allowed even 
if the source column of the used dim
+    attribute and the queried measure are not present in the same derived cube.
+
+    cityState.name is a dimension attribute used in where clause(filter) and 
referenced through join chain name
+    cityState. It is queryable through source column basecube.cityid. 
basecube.cityid and msr1 are not present in the
+    same derived cube. However since cityState.name is only present in the 
case statement, the query is allowed. */
+
+    rewrite("select SUM(CASE WHEN cityState.name ='foo' THEN msr1 END) from 
basecube where " + TWO_DAYS_RANGE, conf);
+  }
+
+  @Test
+  public void testQueryWithDimAttributesNotInSameDerviedCube() throws 
ParseException, SemanticException, LensException {
+
+    /* dim2 and countryid are not present in the same derived cube, hence 
query should be disallowed */
+
+    testFieldsCannotBeQueriedTogetherError("select dim2, countryid, SUM(msr2) 
from basecube where " + TWO_DAYS_RANGE,
+        Arrays.asList("countryid", "dim2"));
+  }
+
+  @Test
+  public void testQueryWithMeasureNotInAnyDerviedCube() throws ParseException, 
SemanticException, LensException {
+
+    /* newmeasure is not present in any derived cube, hence the query should 
be disallowed. */
+
+    testFieldsCannotBeQueriedTogetherError("select newmeasure from basecube 
where "
+        + TWO_DAYS_RANGE, Arrays.asList("newmeasure"));
+  }
+
+  @Test
+  public void testQueryWithReferencedDimAttributeAndMeasure() throws 
SemanticException, ParseException,
+      LensException {
+
+    /* In this query a referenced dimension attribute is used in select 
statement. If the source column for such a
+    dimension attribute and the  queried measure are not present in the same 
derived cube, then query shall be
+    disallowed.
+
+    cityStateCapital is a referenced dimension attribute used in select 
statement. It is queryable through chain source
+    column cityid. cityid and msr1 are not present in the same derived cube, 
hence query shall be disallowed with
+    appropriate exception. */
+
+    testFieldsCannotBeQueriedTogetherError(
+        "select citystatecapital, SUM(msr1) from basecube where " + 
TWO_DAYS_RANGE,
+        Arrays.asList("citystatecapital", "msr1"));
+  }
+
+  private void testFieldsCannotBeQueriedTogetherError(final String testQuery, 
final List<String> conflictingFields)
+    throws ParseException, SemanticException, LensException {
+
+    try {
+
+      rewrite(testQuery, conf);
+      fail("Expected FieldsCannotBeQueriedTogetherException but it didn't 
come");
+    } catch(FieldsCannotBeQueriedTogetherException actualException) {
+
+      SortedSet<String> expectedFields = new 
TreeSet<String>(conflictingFields);
+
+      FieldsCannotBeQueriedTogetherException expectedException =
+          new FieldsCannotBeQueriedTogetherException(new 
ConflictingFields(expectedFields));
+      assertEquals(actualException, expectedException);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/30c67bc5/lens-cube/src/test/java/org/apache/lens/cube/parse/TestBaseCubeQueries.java
----------------------------------------------------------------------
diff --git 
a/lens-cube/src/test/java/org/apache/lens/cube/parse/TestBaseCubeQueries.java 
b/lens-cube/src/test/java/org/apache/lens/cube/parse/TestBaseCubeQueries.java
index e61d807..2a8f082 100644
--- 
a/lens-cube/src/test/java/org/apache/lens/cube/parse/TestBaseCubeQueries.java
+++ 
b/lens-cube/src/test/java/org/apache/lens/cube/parse/TestBaseCubeQueries.java
@@ -66,55 +66,6 @@ public class TestBaseCubeQueries extends TestQueryRewrite {
   public void testColumnErrors() throws Exception {
     SemanticException e;
 
-    e = getSemanticExceptionInRewrite("select dim2, SUM(msr1) from basecube" + 
" where " + TWO_DAYS_RANGE, conf);
-    assertEquals(e.getCanonicalErrorMsg().getErrorCode(), 
ErrorMsg.FIELDS_NOT_QUERYABLE.getErrorCode());
-    assertTrue(e.getMessage().contains("dim2") && 
e.getMessage().contains("msr1"));
-
-    // Query with only measure should pass, since dim is not in where or group 
by
-    String hql = rewrite("select SUM(msr1), "
-      + "SUM(CASE WHEN cityState.name ='foo' THEN msr2"
-      + " WHEN dim2 = 'bar' THEN msr1 ELSE msr2 END) "
-      + "from basecube where " + TWO_DAYS_RANGE, conf);
-    assertNotNull(hql);
-
-    // This query should fail because chain ref in where clause
-    e = getSemanticExceptionInRewrite("select SUM(msr1), "
-      + "SUM(case WHEN cityState.capital ='foo' THEN msr2 ELSE msr1 END) "
-      + "from basecube where " + TWO_DAYS_RANGE + " AND cityState.name='foo'", 
conf);
-    assertEquals(e.getCanonicalErrorMsg().getErrorCode(), 
ErrorMsg.FIELDS_NOT_QUERYABLE.getErrorCode());
-    // Error message should contain chain_name.col_name and it should not 
contain dim attributes in select clause
-    // it should also contain the measure name
-    assertTrue(e.getMessage().contains("citystate.name")
-      && e.getMessage().contains("msr1")
-      && !e.getMessage().contains("capital"), e.getMessage());
-
-
-    e = getSemanticExceptionInRewrite("select cityStateCapital, SUM(msr1) from 
basecube" + " where " + TWO_DAYS_RANGE,
-      conf);
-    assertEquals(e.getCanonicalErrorMsg().getErrorCode(), 
ErrorMsg.FIELDS_NOT_QUERYABLE.getErrorCode());
-    assertTrue(e.getMessage().contains("citystatecapital") && 
e.getMessage().contains("msr1"), e.getMessage());
-
-    e = getSemanticExceptionInRewrite("select cityState.name, SUM(msr1) from 
basecube" + " where " + TWO_DAYS_RANGE,
-      conf);
-    assertEquals(e.getCanonicalErrorMsg().getErrorCode(), 
ErrorMsg.FIELDS_NOT_QUERYABLE.getErrorCode());
-    assertTrue(e.getMessage().contains("citystate.name") && 
e.getMessage().contains("msr1"));
-
-    e = getSemanticExceptionInRewrite("select cubeState.name, SUM(msr1) from 
basecube" + " where " + TWO_DAYS_RANGE,
-      conf);
-    assertEquals(e.getCanonicalErrorMsg().getErrorCode(), 
ErrorMsg.FIELDS_NOT_QUERYABLE.getErrorCode());
-    assertTrue(e.getMessage().contains("cubestate.name") && 
e.getMessage().contains("msr1"));
-
-    e = getSemanticExceptionInRewrite("select dim2, countryid, SUM(msr2) from 
basecube" + " where " + TWO_DAYS_RANGE,
-      conf);
-    assertEquals(e.getCanonicalErrorMsg().getErrorCode(),
-      ErrorMsg.FIELDS_NOT_QUERYABLE.getErrorCode());
-    assertTrue(e.getMessage().contains("dim2") && 
e.getMessage().contains("countryid"));
-
-    e = getSemanticExceptionInRewrite("select newmeasure from basecube" + " 
where " + TWO_DAYS_RANGE, conf);
-    assertEquals(e.getCanonicalErrorMsg().getErrorCode(),
-      ErrorMsg.FIELDS_NOT_QUERYABLE.getErrorCode());
-    assertTrue(e.getMessage().contains("newmeasure"));
-
     e = getSemanticExceptionInRewrite("select msr11 + msr2 from basecube" + " 
where " + TWO_DAYS_RANGE, conf);
     assertEquals(e.getCanonicalErrorMsg().getErrorCode(),
       ErrorMsg.EXPRESSION_NOT_IN_ANY_FACT.getErrorCode());
@@ -141,8 +92,6 @@ public class TestBaseCubeQueries extends TestQueryRewrite {
         }
       }
     );
-
-
   }
 
 

Reply via email to