veghlaci05 commented on code in PR #4060:
URL: https://github.com/apache/hive/pull/4060#discussion_r1221424290


##########
beeline/src/java/org/apache/hive/beeline/schematool/tasks/BeelineScriptExecutor.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.hive.beeline.schematool.tasks;
+
+import org.apache.commons.io.output.NullOutputStream;
+import org.apache.hadoop.hive.metastore.tools.schematool.CommandBuilder;
+import org.apache.hadoop.hive.metastore.tools.schematool.HiveSchemaHelper;
+import 
org.apache.hadoop.hive.metastore.tools.schematool.commandparser.NestedScriptParser;
+import 
org.apache.hadoop.hive.metastore.tools.schematool.scriptexecution.ScriptExecutor;
+import org.apache.hive.beeline.BeeLine;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintStream;
+
+/**
+ * {@link BeeLine} based {@link ScriptExecutor} implementation. Able to 
execute the given scripts using {@link BeeLine} internally.
+ * Can be used to execute scripts against the Hive schema.
+ */
+class BeelineScriptExecutor implements ScriptExecutor {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(BeelineScriptExecutor.class);
+  private static final String LINE_SEPARATOR = "line.separator";
+
+  private final NestedScriptParser dbCommandParser;
+  private final CommandBuilder commandBuilder;
+
+  @Override
+  public void execSql(String scriptDir, String sqlScriptFile) throws 
IOException {
+    // expand the nested script
+    // If the metaDbType is set, this is setting up the information
+    // schema in Hive. That specifically means that the sql commands need
+    // to be adjusted for the underlying RDBMS (correct quotation
+    // strings, etc).
+    String sqlCommands = dbCommandParser.buildCommand(scriptDir, 
sqlScriptFile, true);
+    File tmpFile = File.createTempFile("schematool", ".sql");

Review Comment:
   This file is temporary, it is created using the original script file, and 
modified in a way so Beeline can execute it properly. Once the script is 
executed it is no longer needed. `File.deleteOnExit()` ensures that the file 
will be deleted upon JVM exit (Since SchemaTool is a CLI tool we are talking 
about seconds, or minutes at max).



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to