jackylk commented on a change in pull request #3583: [CARBONDATA-3687] Support 
writing non-transactional carbondata files through hive
URL: https://github.com/apache/carbondata/pull/3583#discussion_r387500926
 
 

 ##########
 File path: 
integration/hive/src/test/java/org/apache/carbondata/hive/HiveTestUtils.java
 ##########
 @@ -0,0 +1,99 @@
+/*
+ * 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.carbondata.hive;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.apache.carbondata.hive.test.server.HiveEmbeddedServer2;
+
+import org.junit.Assert;
+
+/**
+ * A utility class to start and stop the Hive Embedded Server.
+ */
+public abstract class HiveTestUtils {
+
+  private static Connection connection;
+
+  private static HiveEmbeddedServer2 hiveEmbeddedServer2;
+
+  public HiveTestUtils() {
+  }
+
+  private static void setup() {
+    try {
+      File rootPath = new File(HiveTestUtils.class.getResource("/").getPath() 
+ "../../../..");
+      String targetLoc = rootPath.getAbsolutePath() + 
"/integration/hive/target/warehouse";
+      hiveEmbeddedServer2 = new HiveEmbeddedServer2();
+      hiveEmbeddedServer2.start(targetLoc);
+      int port = hiveEmbeddedServer2.getFreePort();
+      connection = DriverManager.getConnection("jdbc:hive2://localhost:" + 
port + "/default", "", "");
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  static Connection getConnection() {
+    if (connection == null) {
+      setup();
+      tearDown();
+    }
+    return connection;
+  }
+
+  public static void tearDown() {
+    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+      try {
+        connection.close();
+        hiveEmbeddedServer2.stop();
+      } catch (SQLException e) {
+        throw new RuntimeException("Unable to close Hive Embedded Server", e);
+      }
+    }));
+  }
+
+  public String getFieldValue(ResultSet rs, String field) throws Exception {
+    while (rs.next()) {
+      System.out.println(rs.getString(1));
+      System.out.println("-- " + rs.getString(2));
+      if (rs.getString(1).toLowerCase().contains(field.toLowerCase())) {
+        return rs.getString(2);
+      }
+    }
+    return "";
+  }
+
+  public boolean checkAnswer(ResultSet actual, ResultSet expected) throws 
SQLException {
+    Assert.assertEquals("Row Count Mismatch: ", expected.getFetchSize(), 
actual.getFetchSize());
+    while(expected.next()) {
 
 Review comment:
   add space before (

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to