[ 
https://issues.apache.org/jira/browse/HIVE-27032?focusedWorklogId=845852&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-845852
 ]

ASF GitHub Bot logged work on HIVE-27032:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 16/Feb/23 11:20
            Start Date: 16/Feb/23 11:20
    Worklog Time Spent: 10m 
      Work Description: 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





Issue Time Tracking
-------------------

    Worklog Id:     (was: 845852)
    Time Spent: 1h  (was: 50m)

> Introduce liquibase for HMS schema evolution
> --------------------------------------------
>
>                 Key: HIVE-27032
>                 URL: https://issues.apache.org/jira/browse/HIVE-27032
>             Project: Hive
>          Issue Type: Improvement
>            Reporter: László Végh
>            Assignee: László Végh
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> Introduce liquibase, and replace current upgrade procedure with it.
> The Schematool CLI API should remain untouched, while under the hood, 
> liquibase should be used for HMS schema evolution.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to