You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/05/30 02:13:35 UTC

[GitHub] [incubator-inlong] gong commented on a diff in pull request #4412: [INLONG-4405][Sort] Support run SQL script

gong commented on code in PR #4412:
URL: https://github.com/apache/incubator-inlong/pull/4412#discussion_r884371048


##########
inlong-sort/sort-core/src/main/java/org/apache/inlong/sort/parser/impl/NativeFlinkSqlParser.java:
##########
@@ -0,0 +1,93 @@
+/*
+ *   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.inlong.sort.parser.impl;
+
+import com.google.common.base.Preconditions;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.inlong.sort.function.RegexpReplaceFirstFunction;
+import org.apache.inlong.sort.parser.Parser;
+import org.apache.inlong.sort.parser.result.FlinkSqlParseResult;
+import org.apache.inlong.sort.parser.result.ParseResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * parse flink sql script file
+ * script file include CREATE TABLE statement
+ */
+public class NativeFlinkSqlParser implements Parser {
+
+    private static final Logger log = LoggerFactory.getLogger(FlinkSqlParser.class);
+
+    private final TableEnvironment tableEnv;
+    private final String statements;
+
+    public NativeFlinkSqlParser(TableEnvironment tableEnv, String statements) {
+        this.tableEnv = tableEnv;
+        this.statements = statements;
+        registerUDF();
+    }
+
+    /**
+     * Register udf
+     */
+    private void registerUDF() {
+        tableEnv.createTemporarySystemFunction("REGEXP_REPLACE_FIRST", RegexpReplaceFirstFunction.class);
+    }
+
+    /**
+     * Get a instance of NativeFlinkSqlParser
+     *
+     * @param tableEnv The tableEnv,it is the execution environment of flink sql
+     * @param statements The statements, it is statement set
+     * @return NativeFlinkSqlParser The flink sql parse handler
+     */
+    public static NativeFlinkSqlParser getInstance(TableEnvironment tableEnv, String statements) {
+        return new NativeFlinkSqlParser(tableEnv, statements);
+    }
+
+
+    /**
+     * parse flink sql script file
+     *
+     * @return ParseResult the result of parsing
+     */
+    @Override
+    public ParseResult parse() {
+        Preconditions.checkNotNull(statements, "sql statement set is null");
+        Preconditions.checkNotNull(tableEnv, "tableEnv is null");
+        List<String> createTableSqls = new ArrayList<>();
+        List<String> insertSqls = new ArrayList<>();
+        String[] statementSet = statements.split(";");

Review Comment:
   > 
   
   json to sql just need to execute `create table` and `insert into`. So here sql keep consistent.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

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