You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by "akshat0395 (via GitHub)" <gi...@apache.org> on 2023/02/16 11:20:20 UTC

[GitHub] [hive] akshat0395 commented on a diff in pull request #4060: HIVE-27032: [Draft] Introduce liquibase for HMS schema evolution

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


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/schematool/CommandBuilder.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.hadoop.hive.metastore.tools.schematool;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+
+public class CommandBuilder {
+
+  private static final Logger LOG = LoggerFactory.getLogger(MetastoreSchemaTool.class);
+
+  private static final String PASSWD_MASK = "[passwd stripped]";
+
+  protected final HiveSchemaHelper.MetaStoreConnectionInfo connectionInfo;
+
+  private boolean verbose = false;
+
+  public CommandBuilder(HiveSchemaHelper.MetaStoreConnectionInfo connectionInfo) {
+    this.connectionInfo = connectionInfo;
+  }
+
+  public CommandBuilder setVerbose(boolean verbose) {
+    this.verbose = verbose;
+    return this;
+  }
+
+  public HiveSchemaHelper.MetaStoreConnectionInfo getConnectionInfo() {
+    return connectionInfo;
+  }
+
+  public boolean isVerbose() {
+    return verbose;
+  }
+
+  public String[] buildToRun(String sqlScriptFile) {
+    return argsWith(connectionInfo.getPassword(), sqlScriptFile);
+  }
+
+  public String buildToLog(String sqlScriptFile) throws IOException {
+    if (verbose) {
+      logScript(sqlScriptFile);
+    }
+    return StringUtils.join(argsWith(PASSWD_MASK, sqlScriptFile), " ");
+  }
+
+  protected String[] argsWith(String password, String sqlScriptFile) {
+    return new String[]
+        {
+            "-u", connectionInfo.getUrl(),
+            "-d", connectionInfo.getDriver(),
+            "-n", connectionInfo.getUsername(),
+            "-p", password,
+            "--isolation=TRANSACTION_READ_COMMITTED",
+            "-f", sqlScriptFile
+        };
+  }
+
+  private void logScript(String sqlScriptFile) throws IOException {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Going to invoke file that contains:");

Review Comment:
   Can we log something like "Invoking {sqScriptFile} containing:"
   This will help verify the filePath as well while Logging the queries. WDYT



##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/schematool/RootTask.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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.hadoop.hive.metastore.tools.schematool;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.HiveMetaException;
+import org.apache.hadoop.hive.metastore.MetaStoreSchemaInfoFactory;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.apache.hadoop.hive.metastore.tools.schematool.task.SchemaToolTask;
+import org.apache.hadoop.hive.metastore.tools.schematool.task.TaskContext;
+
+import java.io.IOException;
+import java.util.Set;
+
+class RootTask extends SchemaToolTask {
+
+  private static final Set<String> VALID_DB_TYPES = ImmutableSet.of(HiveSchemaHelper.DB_DERBY,
+      HiveSchemaHelper.DB_HIVE, HiveSchemaHelper.DB_MSSQL, HiveSchemaHelper.DB_MYSQL,
+      HiveSchemaHelper.DB_POSTGRACE, HiveSchemaHelper.DB_ORACLE);

Review Comment:
   nit: Typo in DB_POSTGRES
   I know this is an old constant, but while we are at it we can fix this. It doesnt have many usage, only 3 including 2 in this file.



##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/tools/schematool/SqlLineScriptExecutor.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.hadoop.hive.metastore.tools.schematool;
+
+import org.apache.commons.io.output.NullOutputStream;
+import org.apache.hadoop.hive.metastore.tools.schematool.hms.ScriptExecutor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import sqlline.SqlLine;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+
+public class SqlLineScriptExecutor implements ScriptExecutor {
+
+  private static final Logger LOG = LoggerFactory.getLogger(SqlLineScriptExecutor.class);
+
+  private final CommandBuilder builder;
+
+  @Override
+  public void execSql(String scriptPath) throws IOException {
+    // run the script using SqlLine
+    SqlLine sqlLine = new SqlLine();
+    ByteArrayOutputStream outputForLog = null;
+    if (!builder.isVerbose()) {
+      OutputStream out;
+      if (LOG.isDebugEnabled()) {
+        out = outputForLog = new ByteArrayOutputStream();
+      } else {
+        out = new NullOutputStream();
+      }
+      sqlLine.setOutputStream(new PrintStream(out));
+      System.setProperty("sqlline.silent", "true");
+    }
+    LOG.info("Going to run command <" + builder.buildToLog(scriptPath) + ">");
+    SqlLine.Status status = sqlLine.begin(builder.buildToRun(scriptPath), null, false);
+    if (LOG.isDebugEnabled() && outputForLog != null) {
+      LOG.debug("Received following output from Sqlline:");
+      LOG.debug(outputForLog.toString("UTF-8"));

Review Comment:
   These 2 can be merged into one LOG.Debug



-- 
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: gitbox-unsubscribe@hive.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org