You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by hi...@apache.org on 2019/05/08 19:56:40 UTC

[incubator-druid] branch master updated: add postgresql meta db table schema configuration property (#7137) (#7183)

This is an automated email from the ASF dual-hosted git repository.

himanshug pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-druid.git


The following commit(s) were added to refs/heads/master by this push:
     new 0ef435a  add postgresql meta db table schema configuration property (#7137) (#7183)
0ef435a is described below

commit 0ef435a16c511181bb97f61b230eeadf50d63535
Author: Jinseon Lee <lo...@gmail.com>
AuthorDate: Thu May 9 04:56:30 2019 +0900

    add postgresql meta db table schema configuration property (#7137) (#7183)
    
    * add postgresql meta db table schema configuration property (#7137)
    
    If the postgresql db schema changes, you must set the configuration
    values.
    You do not need to set it if there is no change from the default schema
    'public'.
    druid.metadata.postgres.dbTableSchema=public
    
    * create postgresql metadb table schema configuration property (#7137)
    If the postgresql db schema changes, you must set the configuration
    values.
    You do not need to set it if there is no change from the default schema
    'public'.
    druid.metadata.postgres.dbTableSchema=public
    check PostgreSQLTablesConfig.java
    
    * modify postgresql readme file. - metadb table schema (#7137)
    If the postgresql db schema changes, you must set the configuration
    values.
    You do not need to set it if there is no change from the default schema
    'public'.
    druid.metadata.postgres.dbTableSchema=public
    check PostgreSQLTablesConfig.java
---
 .../development/extensions-core/postgresql.md      |  2 ++
 .../storage/postgresql/PostgreSQLConnector.java    | 11 ++++--
 .../PostgreSQLMetadataStorageModule.java           |  1 +
 .../storage/postgresql/PostgreSQLTablesConfig.java | 41 ++++++++++++++++++++++
 .../postgresql/PostgreSQLConnectorTest.java        |  3 +-
 5 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/docs/content/development/extensions-core/postgresql.md b/docs/content/development/extensions-core/postgresql.md
index 07a2a78..26f77fc 100644
--- a/docs/content/development/extensions-core/postgresql.md
+++ b/docs/content/development/extensions-core/postgresql.md
@@ -83,3 +83,5 @@ In most cases, the configuration options map directly to the [postgres jdbc conn
 | `druid.metadata.postgres.ssl.sslRootCert` | The full path to the root certificate. | none | no |
 | `druid.metadata.postgres.ssl.sslHostNameVerifier` | The classname of the hostname verifier. | none | no |
 | `druid.metadata.postgres.ssl.sslPasswordCallback` | The classname of the SSL password provider. | none | no |
+| `druid.metadata.postgres.dbTableSchema` | druid meta table schema | `public` | no |
+
diff --git a/extensions-core/postgresql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/postgresql/PostgreSQLConnector.java b/extensions-core/postgresql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/postgresql/PostgreSQLConnector.java
index e234a15..a474a0b 100644
--- a/extensions-core/postgresql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/postgresql/PostgreSQLConnector.java
+++ b/extensions-core/postgresql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/postgresql/PostgreSQLConnector.java
@@ -48,11 +48,14 @@ public class PostgreSQLConnector extends SQLMetadataConnector
 
   private volatile Boolean canUpsert;
 
+  private final String dbTableSchema;
+  
   @Inject
   public PostgreSQLConnector(
       Supplier<MetadataStorageConnectorConfig> config,
       Supplier<MetadataStorageTablesConfig> dbTables,
-      PostgreSQLConnectorConfig connectorConfig
+      PostgreSQLConnectorConfig connectorConfig,
+      PostgreSQLTablesConfig tablesConfig
   )
   {
     super(config, dbTables);
@@ -104,7 +107,8 @@ public class PostgreSQLConnector extends SQLMetadataConnector
     }
 
     this.dbi = new DBI(datasource);
-
+    this.dbTableSchema = tablesConfig.getDbTableSchema();
+    
     log.info("Configured PostgreSQL as metadata storage");
   }
 
@@ -146,8 +150,9 @@ public class PostgreSQLConnector extends SQLMetadataConnector
   public boolean tableExists(final Handle handle, final String tableName)
   {
     return !handle.createQuery(
-        "SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = 'public' AND tablename ILIKE :tableName"
+        "SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = :dbTableSchema AND tablename ILIKE :tableName"
     )
+                  .bind("dbTableSchema", dbTableSchema)
                   .bind("tableName", tableName)
                   .map(StringMapper.FIRST)
                   .list()
diff --git a/extensions-core/postgresql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/postgresql/PostgreSQLMetadataStorageModule.java b/extensions-core/postgresql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/postgresql/PostgreSQLMetadataStorageModule.java
index f10de65..9506edd 100644
--- a/extensions-core/postgresql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/postgresql/PostgreSQLMetadataStorageModule.java
+++ b/extensions-core/postgresql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/postgresql/PostgreSQLMetadataStorageModule.java
@@ -67,6 +67,7 @@ public class PostgreSQLMetadataStorageModule extends SQLMetadataStorageDruidModu
     super.configure(binder);
 
     JsonConfigProvider.bind(binder, "druid.metadata.postgres.ssl", PostgreSQLConnectorConfig.class);
+    JsonConfigProvider.bind(binder, "druid.metadata.postgres", PostgreSQLTablesConfig.class);
 
     PolyBind
         .optionBinder(binder, Key.get(MetadataStorageProvider.class))
diff --git a/extensions-core/postgresql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/postgresql/PostgreSQLTablesConfig.java b/extensions-core/postgresql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/postgresql/PostgreSQLTablesConfig.java
new file mode 100644
index 0000000..82d4543
--- /dev/null
+++ b/extensions-core/postgresql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/postgresql/PostgreSQLTablesConfig.java
@@ -0,0 +1,41 @@
+/*
+ * 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.druid.metadata.storage.postgresql;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class PostgreSQLTablesConfig
+{
+  @JsonProperty
+  private String dbTableSchema = "public";
+
+  public String getDbTableSchema()
+  {
+    return dbTableSchema;
+  }
+
+  @Override
+  public String toString()
+  {
+    return "PostgreSQLTablesConfig{" +
+           ", dbTableSchema='" + dbTableSchema + '\'' +
+          '}';
+  }
+}
diff --git a/extensions-core/postgresql-metadata-storage/src/test/java/org/apache/druid/metadata/storage/postgresql/PostgreSQLConnectorTest.java b/extensions-core/postgresql-metadata-storage/src/test/java/org/apache/druid/metadata/storage/postgresql/PostgreSQLConnectorTest.java
index 222e5d5..bb885d7 100644
--- a/extensions-core/postgresql-metadata-storage/src/test/java/org/apache/druid/metadata/storage/postgresql/PostgreSQLConnectorTest.java
+++ b/extensions-core/postgresql-metadata-storage/src/test/java/org/apache/druid/metadata/storage/postgresql/PostgreSQLConnectorTest.java
@@ -50,7 +50,8 @@ public class PostgreSQLConnectorTest
                 null
             )
         ),
-        new PostgreSQLConnectorConfig()
+        new PostgreSQLConnectorConfig(),
+        new PostgreSQLTablesConfig()
     );
 
     Assert.assertTrue(connector.isTransientException(new SQLException("bummer, connection problem", "08DIE")));


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org