You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kylin.apache.org by GitBox <gi...@apache.org> on 2021/04/12 10:00:39 UTC

[GitHub] [kylin] zheniantoushipashi opened a new pull request #1628: [KYLIN-4554] validate filter condition on model saving

zheniantoushipashi opened a new pull request #1628:
URL: https://github.com/apache/kylin/pull/1628


   verify filter condition using the following login
   
   1 select * from tableName where {filterCondition} pass   calcite  parse
   
   2 all column in filter condition must be model table column


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kylin] hit-lacus commented on a change in pull request #1628: [KYLIN-4554] validate filter condition on model saving

Posted by GitBox <gi...@apache.org>.
hit-lacus commented on a change in pull request #1628:
URL: https://github.com/apache/kylin/pull/1628#discussion_r612070903



##########
File path: core-metadata/src/main/java/org/apache/kylin/metadata/util/ModelUtil.java
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.metadata.util;
+
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlSelect;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.util.SqlBasicVisitor;
+import org.apache.kylin.metadata.model.TableDesc;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Lists;
+
+public class ModelUtil {
+
+    private static final Logger logger = LoggerFactory.getLogger(ModelUtil.class);
+
+    public static void verifyFilterCondition(String factTableName, String filterCondition, TableDesc tableDesc)
+            throws Exception {
+        StringBuilder checkSql = new StringBuilder();
+        checkSql.append("select * from ").append(factTableName).append(" where ").append(filterCondition);
+
+        SqlCall inputToNode = (SqlCall) parse(doubleQuotaKeywordDefault(checkSql.toString()));
+        SqlVerify sqlVerify = new SqlVerify(tableDesc);
+        sqlVerify.visit(inputToNode);
+
+    }
+
+    public static SqlNode parse(String sql) throws Exception {
+        SqlParser.ConfigBuilder parserBuilder = SqlParser.configBuilder().setIdentifierMaxLength(300);
+        SqlParser sqlParser = SqlParser.create(sql, parserBuilder.build());
+        return sqlParser.parseQuery();
+    }
+
+    private static class SqlVerify extends SqlBasicVisitor {
+
+        private TableDesc tableDesc;
+
+        SqlVerify(TableDesc tableDesc) {
+            this.tableDesc = tableDesc;
+        }
+
+        @Override
+        public Object visit(SqlCall call) {
+            SqlSelect select = (SqlSelect) call;
+            WhereColumnVerify.verify(select.getWhere(), tableDesc);
+            return null;
+        }
+    }
+
+    private static class WhereColumnVerify extends SqlBasicVisitor {
+
+        private List<String> allSqlIdentifier = Lists.newArrayList();
+
+        static void verify(SqlNode whereNode, TableDesc tableDesc) {
+            WhereColumnVerify whereColumnVerify = new WhereColumnVerify();
+            whereNode.accept(whereColumnVerify);
+            whereColumnVerify.allSqlIdentifier.stream().forEach(col -> {
+                if (tableDesc.findColumnByName(col) == null) {
+                    String verifyError = String.format(Locale.ROOT,
+                            "filter condition col: %s is not a column in the table ", col);
+                    logger.error(verifyError);
+                    throw new IllegalArgumentException(verifyError);
+                }
+            });
+        }
+
+        public Object visit(SqlIdentifier id) {
+            allSqlIdentifier.add(id.names.get(0));
+            return null;
+        }
+    }
+
+    public static String doubleQuotaKeywordDefault(String sql) {

Review comment:
       `Quota` or `Quote` ?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kylin] hit-lacus merged pull request #1628: [KYLIN-4554] validate filter condition on model saving

Posted by GitBox <gi...@apache.org>.
hit-lacus merged pull request #1628:
URL: https://github.com/apache/kylin/pull/1628


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [kylin] zheniantoushipashi commented on a change in pull request #1628: [KYLIN-4554] validate filter condition on model saving

Posted by GitBox <gi...@apache.org>.
zheniantoushipashi commented on a change in pull request #1628:
URL: https://github.com/apache/kylin/pull/1628#discussion_r612072018



##########
File path: core-metadata/src/main/java/org/apache/kylin/metadata/util/ModelUtil.java
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.metadata.util;
+
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlSelect;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.util.SqlBasicVisitor;
+import org.apache.kylin.metadata.model.TableDesc;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Lists;
+
+public class ModelUtil {
+
+    private static final Logger logger = LoggerFactory.getLogger(ModelUtil.class);
+
+    public static void verifyFilterCondition(String factTableName, String filterCondition, TableDesc tableDesc)
+            throws Exception {
+        StringBuilder checkSql = new StringBuilder();
+        checkSql.append("select * from ").append(factTableName).append(" where ").append(filterCondition);
+
+        SqlCall inputToNode = (SqlCall) parse(doubleQuotaKeywordDefault(checkSql.toString()));
+        SqlVerify sqlVerify = new SqlVerify(tableDesc);
+        sqlVerify.visit(inputToNode);
+
+    }
+
+    public static SqlNode parse(String sql) throws Exception {
+        SqlParser.ConfigBuilder parserBuilder = SqlParser.configBuilder().setIdentifierMaxLength(300);
+        SqlParser sqlParser = SqlParser.create(sql, parserBuilder.build());
+        return sqlParser.parseQuery();
+    }
+
+    private static class SqlVerify extends SqlBasicVisitor {
+
+        private TableDesc tableDesc;
+
+        SqlVerify(TableDesc tableDesc) {
+            this.tableDesc = tableDesc;
+        }
+
+        @Override
+        public Object visit(SqlCall call) {
+            SqlSelect select = (SqlSelect) call;
+            WhereColumnVerify.verify(select.getWhere(), tableDesc);
+            return null;
+        }
+    }
+
+    private static class WhereColumnVerify extends SqlBasicVisitor {
+
+        private List<String> allSqlIdentifier = Lists.newArrayList();
+
+        static void verify(SqlNode whereNode, TableDesc tableDesc) {
+            WhereColumnVerify whereColumnVerify = new WhereColumnVerify();
+            whereNode.accept(whereColumnVerify);
+            whereColumnVerify.allSqlIdentifier.stream().forEach(col -> {
+                if (tableDesc.findColumnByName(col) == null) {
+                    String verifyError = String.format(Locale.ROOT,
+                            "filter condition col: %s is not a column in the table ", col);
+                    logger.error(verifyError);
+                    throw new IllegalArgumentException(verifyError);
+                }
+            });
+        }
+
+        public Object visit(SqlIdentifier id) {
+            allSqlIdentifier.add(id.names.get(0));
+            return null;
+        }
+    }
+
+    public static String doubleQuotaKeywordDefault(String sql) {

Review comment:
       got 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org