minor, refine query error message

Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/a7fd3b15
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/a7fd3b15
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/a7fd3b15

Branch: refs/heads/master
Commit: a7fd3b1541177a71bf3dded8b193b8bf1eda992f
Parents: 7f8f039
Author: liveandevil <1361605...@qq.com>
Authored: Wed Sep 20 15:09:45 2017 +0800
Committer: Dong Li <lid...@apache.org>
Committed: Wed Sep 20 16:05:15 2017 +0800

----------------------------------------------------------------------
 .../kylin/common/debug/BackdoorToggles.java     | 14 ++++
 .../kylin/query/routing/RealizationCheck.java   | 47 ++++++++++++-
 .../kylin/query/routing/RealizationChooser.java | 14 ++++
 .../query/routing/RealizationCheckTest.java     | 73 ++++++++++++++++++++
 4 files changed, 146 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/a7fd3b15/core-common/src/main/java/org/apache/kylin/common/debug/BackdoorToggles.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/debug/BackdoorToggles.java 
b/core-common/src/main/java/org/apache/kylin/common/debug/BackdoorToggles.java
index 88c7c16..7664022 100644
--- 
a/core-common/src/main/java/org/apache/kylin/common/debug/BackdoorToggles.java
+++ 
b/core-common/src/main/java/org/apache/kylin/common/debug/BackdoorToggles.java
@@ -97,6 +97,10 @@ public class BackdoorToggles {
         return getString(DEBUG_TOGGLE_DUMPED_PARTITION_DIR);
     }
 
+    public static boolean getCheckAllModels(){
+        return getBoolean(DEBUG_TOGGLE_CHECK_ALL_MODELS);
+    }
+
     public static int getQueryTimeout() {
         String v = getString(DEBUG_TOGGLE_QUERY_TIMEOUT);
         if (v == null)
@@ -271,4 +275,14 @@ public class BackdoorToggles {
      }
      */
     public final static String ATTR_STATEMENT_MAX_ROWS = 
"ATTR_STATEMENT_MAX_ROWS";
+
+    /**
+     * set DEBUG_TOGGLE_CHECK_ALL_MODELS="true" to check all OlapContexts when 
selecting realization
+     *
+     example:(put it into request body)
+     "backdoorToggles": {
+     "DEBUG_TOGGLE_CHECK_ALL_MODELS": "true"
+     }
+     */
+    public final static String DEBUG_TOGGLE_CHECK_ALL_MODELS = 
"DEBUG_TOGGLE_CHECK_ALL_MODELS";
 }

http://git-wip-us.apache.org/repos/asf/kylin/blob/a7fd3b15/query/src/main/java/org/apache/kylin/query/routing/RealizationCheck.java
----------------------------------------------------------------------
diff --git 
a/query/src/main/java/org/apache/kylin/query/routing/RealizationCheck.java 
b/query/src/main/java/org/apache/kylin/query/routing/RealizationCheck.java
index ec630cb..827b357 100644
--- a/query/src/main/java/org/apache/kylin/query/routing/RealizationCheck.java
+++ b/query/src/main/java/org/apache/kylin/query/routing/RealizationCheck.java
@@ -86,12 +86,15 @@ public class RealizationCheck {
             List<IncapableReason> reasons = Lists.newArrayList(reason);
             modelIncapableReasons.put(modelDesc, reasons);
         } else {
-            modelIncapableReasons.get(modelDesc).add(reason);
+            List<IncapableReason> incapableReasons = 
modelIncapableReasons.get(modelDesc);
+            if (!incapableReasons.contains(reason))
+                incapableReasons.add(reason);
         }
     }
 
     public void addCapableModel(DataModelDesc modelDesc) {
-        this.capableModels.add(modelDesc);
+        if (!this.capableModels.contains(modelDesc))
+            this.capableModels.add(modelDesc);
     }
 
     public void addModelIncapableReason(DataModelDesc modelDesc, 
List<IncapableReason> reasons) {
@@ -238,5 +241,45 @@ public class RealizationCheck {
         public Collection<OLAPTableScan> getNotFoundTables() {
             return notFoundTables;
         }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o)
+                return true;
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            IncapableReason that = (IncapableReason) o;
+
+            if (incapableType != that.incapableType)
+                return false;
+            if (notFoundColumns != null ? 
!notFoundColumns.equals(that.notFoundColumns) : that.notFoundColumns != null)
+                return false;
+            if (notFoundDimensions != null ? 
!notFoundDimensions.equals(that.notFoundDimensions)
+                    : that.notFoundDimensions != null)
+                return false;
+            if (notFoundMeasures != null ? 
!notFoundMeasures.equals(that.notFoundMeasures)
+                    : that.notFoundMeasures != null)
+                return false;
+            if (unmatchedDimensions != null ? 
!unmatchedDimensions.equals(that.unmatchedDimensions)
+                    : that.unmatchedDimensions != null)
+                return false;
+            if (unmatchedAggregations != null ? 
!unmatchedAggregations.equals(that.unmatchedAggregations)
+                    : that.unmatchedAggregations != null)
+                return false;
+            return notFoundTables != null ? 
notFoundTables.equals(that.notFoundTables) : that.notFoundTables == null;
+        }
+
+        @Override
+        public int hashCode() {
+            int result = incapableType != null ? incapableType.hashCode() : 0;
+            result = 31 * result + (notFoundColumns != null ? 
notFoundColumns.hashCode() : 0);
+            result = 31 * result + (notFoundDimensions != null ? 
notFoundDimensions.hashCode() : 0);
+            result = 31 * result + (notFoundMeasures != null ? 
notFoundMeasures.hashCode() : 0);
+            result = 31 * result + (unmatchedDimensions != null ? 
unmatchedDimensions.hashCode() : 0);
+            result = 31 * result + (unmatchedAggregations != null ? 
unmatchedAggregations.hashCode() : 0);
+            result = 31 * result + (notFoundTables != null ? 
notFoundTables.hashCode() : 0);
+            return result;
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/kylin/blob/a7fd3b15/query/src/main/java/org/apache/kylin/query/routing/RealizationChooser.java
----------------------------------------------------------------------
diff --git 
a/query/src/main/java/org/apache/kylin/query/routing/RealizationChooser.java 
b/query/src/main/java/org/apache/kylin/query/routing/RealizationChooser.java
index 56580c6..4b52de6 100644
--- a/query/src/main/java/org/apache/kylin/query/routing/RealizationChooser.java
+++ b/query/src/main/java/org/apache/kylin/query/routing/RealizationChooser.java
@@ -25,6 +25,7 @@ import java.util.Set;
 import java.util.TreeMap;
 
 import org.apache.kylin.common.KylinConfig;
+import org.apache.kylin.common.debug.BackdoorToggles;
 import org.apache.kylin.cube.CubeInstance;
 import org.apache.kylin.metadata.model.ColumnDesc;
 import org.apache.kylin.metadata.model.DataModelDesc;
@@ -69,6 +70,19 @@ public class RealizationChooser {
             throw new NoRealizationFoundException("No model found for " + 
toErrorMsg(context));
         }
 
+        //check all models to collect error message, just for check
+        if (BackdoorToggles.getCheckAllModels()) {
+            for (Map.Entry<DataModelDesc, Set<IRealization>> entry : 
modelMap.entrySet()) {
+                final DataModelDesc model = entry.getKey();
+                final Map<String, String> aliasMap = matches(model, context);
+                if (aliasMap != null) {
+                    fixModel(context, model, aliasMap);
+                    QueryRouter.selectRealization(context, entry.getValue());
+                    unfixModel(context);
+                }
+            }
+        }
+
         for (Map.Entry<DataModelDesc, Set<IRealization>> entry : 
modelMap.entrySet()) {
             final DataModelDesc model = entry.getKey();
             final Map<String, String> aliasMap = matches(model, context);

http://git-wip-us.apache.org/repos/asf/kylin/blob/a7fd3b15/query/src/test/java/org/apache/kylin/query/routing/RealizationCheckTest.java
----------------------------------------------------------------------
diff --git 
a/query/src/test/java/org/apache/kylin/query/routing/RealizationCheckTest.java 
b/query/src/test/java/org/apache/kylin/query/routing/RealizationCheckTest.java
new file mode 100644
index 0000000..b5258d8
--- /dev/null
+++ 
b/query/src/test/java/org/apache/kylin/query/routing/RealizationCheckTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.kylin.query.routing;
+
+import org.apache.kylin.common.util.LocalFileMetadataTestCase;
+import org.apache.kylin.cube.CubeDescManager;
+import org.apache.kylin.cube.CubeInstance;
+import org.apache.kylin.cube.model.CubeDesc;
+import org.apache.kylin.metadata.model.DataModelDesc;
+import org.apache.kylin.metadata.model.TblColRef;
+import org.apache.kylin.metadata.realization.IRealization;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+
+public class RealizationCheckTest extends LocalFileMetadataTestCase {
+    @Before
+    public void setUp() throws Exception {
+        this.createTestMetadata();
+    }
+
+    @After
+    public void after() throws Exception {
+        this.cleanupTestMetadata();
+    }
+
+    @Test
+    public void testRealizationCheck() {
+        RealizationCheck realizationCheck = new RealizationCheck();
+        CubeDesc cubeDesc = 
CubeDescManager.getInstance(getTestConfig()).getCubeDesc("ssb");
+        DataModelDesc dataModelDesc = cubeDesc.getModel();
+        IRealization iRealization = CubeInstance.create("ssb", cubeDesc);
+        realizationCheck.addCubeIncapableReason(iRealization,
+                
RealizationCheck.IncapableReason.create(RealizationCheck.IncapableType.CUBE_NOT_CONTAIN_ALL_COLUMN));
+        realizationCheck.addCubeIncapableReason(iRealization,
+                
RealizationCheck.IncapableReason.create(RealizationCheck.IncapableType.CUBE_NOT_CONTAIN_ALL_COLUMN));
+        Assert.assertTrue(realizationCheck.getCubeIncapableReasons().size() == 
1);
+
+        realizationCheck.addModelIncapableReason(dataModelDesc,
+                
RealizationCheck.IncapableReason.create(RealizationCheck.IncapableType.CUBE_NOT_CONTAIN_ALL_COLUMN));
+        realizationCheck.addModelIncapableReason(dataModelDesc,
+                
RealizationCheck.IncapableReason.create(RealizationCheck.IncapableType.CUBE_NOT_CONTAIN_ALL_MEASURE));
+        realizationCheck.addModelIncapableReason(dataModelDesc,
+                
RealizationCheck.IncapableReason.notContainAllColumn(Lists.<TblColRef> 
newArrayList()));
+        realizationCheck.addModelIncapableReason(dataModelDesc,
+                
RealizationCheck.IncapableReason.notContainAllColumn(Lists.<TblColRef> 
newArrayList()));
+        Assert.assertTrue(realizationCheck.getModelIncapableReasons().size() 
== 1);
+        
Assert.assertTrue(realizationCheck.getModelIncapableReasons().get(dataModelDesc).size()
 == 3);
+
+        realizationCheck.addModelIncapableReason(dataModelDesc, 
RealizationCheck.IncapableReason
+                .notContainAllColumn(Lists.<TblColRef> 
newArrayList(dataModelDesc.findColumn("LO_DATE"))));
+        Assert.assertTrue(realizationCheck.getModelIncapableReasons().size() 
== 1);
+        
Assert.assertTrue(realizationCheck.getModelIncapableReasons().get(dataModelDesc).size()
 == 4);
+    }
+}

Reply via email to