paul-rogers commented on a change in pull request #2060: DRILL-7706: Implement 
Drill RDBMS Metastore for Tables component
URL: https://github.com/apache/drill/pull/2060#discussion_r410830741
 
 

 ##########
 File path: 
metastore/rdbms-metastore/src/main/java/org/apache/drill/metastore/rdbms/QueryExecutorProvider.java
 ##########
 @@ -0,0 +1,81 @@
+/*
+ * 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.drill.metastore.rdbms;
+
+import com.zaxxer.hikari.HikariDataSource;
+import org.jooq.DSLContext;
+import org.jooq.SQLDialect;
+import org.jooq.impl.DSL;
+import org.jooq.tools.jdbc.JDBCUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * Provides SQL queries executor configured based on given data source and SQL 
dialect.
+ */
+public class QueryExecutorProvider implements AutoCloseable {
+
+  private static final Logger logger = 
LoggerFactory.getLogger(QueryExecutorProvider.class);
+
+  private final HikariDataSource dataSource;
+  private final SQLDialect dialect;
+
+  public QueryExecutorProvider(HikariDataSource dataSource) {
+    this.dataSource = dataSource;
+    this.dialect = defineDialect();
+  }
+
+  /**
+   * Provides query executor which can be used to execute various SQL 
statements.
+   * Executor transforms programmatically created queries into configured SQL 
dialect,
+   * executes them using connections from provided data source. Allows to 
execute
+   * SQL queries in transaction.
+   * Note: always close executor to release open connections.
+   *
+   * @return query executor
+   */
+  public DSLContext executor() {
+    return DSL.using(dataSource, dialect);
+  }
+
+  @Override
+  public void close() {
+    dataSource.close();
+  }
+
+  /**
+   * Defines SQL dialect based on data source connection.
+   * If unable to define the dialect, uses {@link SQLDialect#DEFAULT}.
+   *
+   * @return SQL dialect
+   */
+  private SQLDialect defineDialect() {
+    SQLDialect dialect = SQLDialect.DEFAULT;
+    try (Connection connection = dataSource.getConnection()) {
+      dialect = JDBCUtils.dialect(connection);
+    } catch (SQLException e) {
+      logger.debug("Unable to connect to data source in order to define SQL 
dialect: {}", e.getMessage(), e);
 
 Review comment:
   This seems like exactly the kind of problem a typical user (that would be 
me) will have. Stuff won't work for some dumb reason, but the only indication 
is a debug-level log message.
   
   Should we:
   
   * Dedicate a logger to narrating metastore start up and errors?
   * Explain in the user guide how to turn on the logger, and show what a 
successful startup is like.
   
   Example:
   
   ... Found drill-metastore-override.conf in /path/to/file.
   ... Metastore is configured to use the MySQL database with url "...", user 
"bob".
   ... ERROR: MySQL JDBC driver not found on the class path.
   
   Or...
   
   ... Connection to MySQL with url "..." failed. Is user "bob", no password 
correct?
   
   Or...
   
   
   ... Database Oracle7 is not supported by Liquibase.
   
   Or
   
   ... Unable to create Drill metastore table TABLES. Does user 'bob' have 
correct permissions?

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


With regards,
Apache Git Services

Reply via email to