[ 
https://issues.apache.org/jira/browse/DRILL-7706?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17086803#comment-17086803
 ] 

ASF GitHub Bot commented on DRILL-7706:
---------------------------------------

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

 ##########
 File path: 
metastore/rdbms-metastore/src/main/java/org/apache/drill/metastore/rdbms/RdbmsMetastore.java
 ##########
 @@ -0,0 +1,166 @@
+/*
+ * 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.typesafe.config.Config;
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
+import liquibase.Liquibase;
+import liquibase.database.Database;
+import liquibase.database.DatabaseFactory;
+import liquibase.database.jvm.JdbcConnection;
+import liquibase.resource.ClassLoaderResourceAccessor;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.metastore.Metastore;
+import org.apache.drill.metastore.components.tables.Tables;
+import org.apache.drill.metastore.components.views.Views;
+import org.apache.drill.metastore.config.MetastoreConfigConstants;
+import org.apache.drill.metastore.rdbms.components.tables.RdbmsTables;
+import org.apache.drill.metastore.rdbms.config.RdbmsConfigConstants;
+import org.apache.drill.metastore.rdbms.exception.RdbmsMetastoreException;
+import org.jooq.SQLDialect;
+import org.jooq.tools.jdbc.JDBCUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.sql.DataSource;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.sql.Connection;
+import java.util.Properties;
+
+/**
+ * RDBMS Drill Metastore implementation that creates necessary tables using 
Liquibase,
+ * initializes data source using provided config.
+ */
+public class RdbmsMetastore implements Metastore {
+
+  private static final Logger logger = 
LoggerFactory.getLogger(RdbmsMetastore.class);
+
+  private static final String LIQUIBASE_CHANGELOG_FILE = 
"db/changelog/changelog.yaml";
+
+  private final QueryExecutorProvider executorProvider;
+
+  public RdbmsMetastore(DrillConfig config) {
+    HikariDataSource dataSource = dataSource(config);
+    this.executorProvider = new QueryExecutorProvider(dataSource);
+    initTables(dataSource);
+  }
+
+  @Override
+  public Tables tables() {
+    return new RdbmsTables(executorProvider);
+  }
+
+  @Override
+  public Views views() {
+    throw new UnsupportedOperationException("Views metadata support is not 
implemented");
+  }
+
+  @Override
+  public void close() {
+    executorProvider.close();
+  }
+
+  /**
+   * Prepares database before initializing data source based on its type,
+   * initializes {@link HikariDataSource} instance and configures it based on 
given
+   * Metastore configuration.
+   * Basic parameters such as driver, url, user name and password are set 
using setters.
+   * Other source parameters are set dynamically through the properties. See 
the list
+   * of available Hikari properties: <a 
href="https://github.com/brettwooldridge/HikariCP";>.
+   *
+   * @param config Metastore config
+   * @return Hikari data source instance
+   * @throws RdbmsMetastoreException if unable to configure Hikari data source
+   */
+  private HikariDataSource dataSource(DrillConfig config) {
+    prepareDatabase(config);
+    try {
+      Properties properties = new Properties();
+      if (config.hasPath(RdbmsConfigConstants.DATA_SOURCE_PROPERTIES)) {
+        Config propertiesConfig = 
config.getConfig(RdbmsConfigConstants.DATA_SOURCE_PROPERTIES);
+        propertiesConfig.entrySet().forEach(e -> properties.put(e.getKey(), 
e.getValue().unwrapped()));
+      }
+      HikariConfig hikariConfig = new HikariConfig(properties);
+      
hikariConfig.setDriverClassName(config.getString(RdbmsConfigConstants.DATA_SOURCE_DRIVER));
+      
hikariConfig.setJdbcUrl(config.getString(RdbmsConfigConstants.DATA_SOURCE_URL));
+      if (config.hasPath(RdbmsConfigConstants.DATA_SOURCE_USER_NAME)) {
+        
hikariConfig.setUsername(config.getString(RdbmsConfigConstants.DATA_SOURCE_USER_NAME));
+      }
+      if (config.hasPath(RdbmsConfigConstants.DATA_SOURCE_PASSWORD)) {
+        
hikariConfig.setPassword(config.getString(RdbmsConfigConstants.DATA_SOURCE_PASSWORD));
+      }
+      return new HikariDataSource(hikariConfig);
+    } catch (RuntimeException e) {
+      throw new RdbmsMetastoreException("Unable to init RDBMS Metastore data 
source: " + e.getMessage(), e);
 
 Review comment:
   This is exactly the kind of information we'll need when a user on the 
mailing list runs into problems. But, we're not providing much context. 
Consider using `UserException` so that we can add lots of context and to ensure 
the error is logged.
 
----------------------------------------------------------------
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]


> Drill RDBMS Metastore
> ---------------------
>
>                 Key: DRILL-7706
>                 URL: https://issues.apache.org/jira/browse/DRILL-7706
>             Project: Apache Drill
>          Issue Type: New Feature
>    Affects Versions: 1.17.0
>            Reporter: Arina Ielchiieva
>            Assignee: Arina Ielchiieva
>            Priority: Major
>             Fix For: 1.18.0
>
>
> Currently Drill has only one Metastore implementation based on Iceberg 
> tables. Iceberg tables are file based storage that supports concurrent writes 
> / reads but required to be placed on distributed file system. 
> This Jira aims to implement Drill RDBMS Metastore which will store Drill 
> Metastore metadata in the database of the user's choice. Currently, 
> PostgreSQL and MySQL databases are supported, others might work as well but 
> no testing was done. Also out of box for demonstration / testing purposes 
> Drill will setup SQLite file based embedded database but this is only 
> applicable for Drill in embedded mode.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to