Advertisement
Guest User

ClickhouseConf.java

a guest
Mar 18th, 2020
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.18 KB | None | 0 0
  1. /*
  2.  * Copyright (C) 2017-2018 Dremio Corporation
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *     http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16. package com.dremio.exec.store.jdbc.conf;
  17.  
  18. import static com.google.common.base.Preconditions.checkNotNull;
  19.  
  20. import org.hibernate.validator.constraints.NotBlank;
  21.  
  22. import com.dremio.exec.catalog.conf.DisplayMetadata;
  23. import com.dremio.exec.catalog.conf.NotMetadataImpacting;
  24. import com.dremio.exec.catalog.conf.SourceType;
  25. import com.dremio.exec.server.SabotContext;
  26. import com.dremio.exec.store.jdbc.CloseableDataSource;
  27. import com.dremio.exec.store.jdbc.DataSources;
  28. import com.dremio.exec.store.jdbc.JdbcStoragePlugin;
  29. import com.dremio.exec.store.jdbc.JdbcStoragePlugin.Config;
  30. import com.dremio.exec.store.jdbc.dialect.arp.ArpDialect;
  31. import com.google.common.annotations.VisibleForTesting;
  32. import com.dremio.exec.catalog.conf.Secret;
  33.  
  34. import io.protostuff.Tag;
  35.  
  36. /**
  37.  * Configuration for Clickhouse sources.
  38.  */
  39. @SourceType(value = "CLICKHOUSE", label = "Clickhouse")
  40. public class ClickhouseConf extends AbstractArpConf<ClickhouseConf> {
  41.   private static final String ARP_FILENAME = "arp/implementation/clickhouse-arp.yaml";
  42.   private static final ArpDialect ARP_DIALECT =
  43.       AbstractArpConf.loadArpFile(ARP_FILENAME, (ArpDialect::new));
  44.   private static final String DRIVER = "ru.yandex.clickhouse.ClickHouseDriver";
  45.  
  46.   @NotBlank
  47.   @Tag(1)
  48.   @DisplayMetadata(label = "Host")
  49.   public String host;
  50.  
  51.   @NotBlank
  52.   @Tag(2)
  53.   @DisplayMetadata(label = "Port")
  54.   public String port;
  55.  
  56.   @Tag(3)
  57.   @DisplayMetadata(label = "Database")
  58.   public String database;
  59.  
  60.   @NotBlank
  61.   @Tag(4)
  62.   @DisplayMetadata(label = "User")
  63.   public String user;
  64.  
  65.   @NotBlank
  66.   @Secret
  67.   @Tag(5)
  68.   @DisplayMetadata(label = "Password")
  69.   public String password;
  70.  
  71.   @VisibleForTesting
  72.   public String toJdbcConnectionString() {
  73.     return String.format("jdbc:clickhouse://%s:%s/%s?user=%s&password=%s", host, port, database, user, password);
  74.   }
  75.  
  76.   @Override
  77.   @VisibleForTesting
  78.   public Config toPluginConfig(SabotContext context) {
  79.     return JdbcStoragePlugin.Config.newBuilder()
  80.         .withDialect(getDialect())
  81.         .withDatasourceFactory(this::newDataSource)
  82.         .clearHiddenSchemas()
  83.         //.addHiddenSchema("SYSTEM")
  84.         .build();
  85.   }
  86.  
  87.   private CloseableDataSource newDataSource() {
  88.     return DataSources.newGenericConnectionPoolDataSource(DRIVER,
  89.       toJdbcConnectionString(), user, password, null, DataSources.CommitMode.DRIVER_SPECIFIED_COMMIT_MODE);
  90.   }
  91.  
  92.   @Override
  93.   public ArpDialect getDialect() {
  94.     return ARP_DIALECT;
  95.   }
  96.  
  97.   @VisibleForTesting
  98.   public static ArpDialect getDialectSingleton() {
  99.     return ARP_DIALECT;
  100.   }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement