diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/AbstractDatabendResultSet.java b/databend-jdbc/src/main/java/com/databend/jdbc/AbstractDatabendResultSet.java index b44272d8..2eec7742 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/AbstractDatabendResultSet.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/AbstractDatabendResultSet.java @@ -1,6 +1,5 @@ package com.databend.jdbc; -import com.databend.client.DatabendClient; import com.databend.client.QueryResults; import com.databend.client.QueryRowField; import com.databend.client.data.ColumnTypeHandler; @@ -365,7 +364,7 @@ private Object column(int index) if (value == null || value.toString().equals("NULL")) { wasNull.set(true); return null; - }else { + } else { wasNull.set(false); } diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/ConnectionProperties.java b/databend-jdbc/src/main/java/com/databend/jdbc/ConnectionProperties.java index a5994a76..391f936a 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/ConnectionProperties.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/ConnectionProperties.java @@ -3,9 +3,7 @@ import com.databend.client.PaginationOptions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import org.checkerframework.checker.units.qual.C; -import java.sql.Connection; import java.util.Map; import java.util.Optional; import java.util.Set; @@ -158,7 +156,7 @@ public LoadBalancingPolicy() { } } - private static class AutoDiscovery extends AbstractConnectionProperty { + private static class AutoDiscovery extends AbstractConnectionProperty { public AutoDiscovery() { super("auto_discovery", Optional.of("false"), NOT_REQUIRED, ALLOWED, BOOLEAN_CONVERTER); } diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/ConnectionProperty.java b/databend-jdbc/src/main/java/com/databend/jdbc/ConnectionProperty.java index 1a45893f..3c2db693 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/ConnectionProperty.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/ConnectionProperty.java @@ -15,8 +15,7 @@ import static java.util.Locale.ENGLISH; import static java.util.Objects.requireNonNull; -interface ConnectionProperty -{ +interface ConnectionProperty { String getKey(); Optional getDefault(); @@ -31,8 +30,7 @@ Optional getValue(Properties properties) throws SQLException; default T getRequiredValue(Properties properties) - throws SQLException - { + throws SQLException { return getValue(properties).orElseThrow(() -> new SQLException(format("Connection property '%s' is required", getKey()))); } @@ -42,8 +40,7 @@ void validate(Properties properties) } abstract class AbstractConnectionProperty - implements ConnectionProperty -{ + implements ConnectionProperty { protected static final Predicate NOT_REQUIRED = properties -> false; protected static final Predicate ALLOWED = properties -> true; protected static final Converter STRING_CONVERTER = value -> value; @@ -70,17 +67,16 @@ abstract class AbstractConnectionProperty private final String[] choices; protected AbstractConnectionProperty(String key, Optional defaultValue, - Predicate isRequired, Predicate isAllowed, Converter converter, String[] choices, String[] aliases) - { + Predicate isRequired, Predicate isAllowed, Converter converter, String[] choices, String[] aliases) { this.key = requireNonNull(key, "key is null"); this.defaultValue = requireNonNull(defaultValue, "defaultValue is null"); this.isRequired = requireNonNull(isRequired, "isRequired is null"); this.isAllowed = requireNonNull(isAllowed, "isAllowed is null"); this.converter = requireNonNull(converter, "converter is null"); if (choices == null || choices.length == 0) { - this.choices = inferChoices(converter);; - } - else { + this.choices = inferChoices(converter); + ; + } else { this.choices = choices; } } @@ -90,8 +86,7 @@ protected AbstractConnectionProperty( Optional defaultValue, Predicate isRequired, Predicate isAllowed, - Converter converter) - { + Converter converter) { this.key = requireNonNull(key, "key is null"); this.defaultValue = requireNonNull(defaultValue, "defaultValue is null"); this.isRequired = requireNonNull(isRequired, "isRequired is null"); @@ -105,8 +100,7 @@ protected AbstractConnectionProperty( String key, Predicate required, Predicate allowed, - Converter converter) - { + Converter converter) { this(key, Optional.empty(), required, allowed, converter); } @@ -115,18 +109,15 @@ protected AbstractConnectionProperty( Predicate required, Predicate allowed, Converter converter, - String[] aliases) - { + String[] aliases) { this(key, Optional.empty(), required, allowed, converter, null, aliases); } - protected static Predicate checkedPredicate(CheckedPredicate predicate) - { + protected static Predicate checkedPredicate(CheckedPredicate predicate) { return t -> { try { return predicate.test(t); - } - catch (SQLException e) { + } catch (SQLException e) { return false; } }; @@ -134,49 +125,43 @@ protected static Predicate checkedPredicate(CheckedPredicate predicate private String[] inferChoices(Converter converter) { String[] choices = null; - Class type = new TypeToken(getClass()) {}.getRawType(); + Class type = new TypeToken(getClass()) { + }.getRawType(); if (type == Boolean.class) { - choices = new String[] {"true", "false"}; - } - else if (Enum.class.isAssignableFrom(type)) { + choices = new String[]{"true", "false"}; + } else if (Enum.class.isAssignableFrom(type)) { choices = Stream.of(type.getEnumConstants()) .map(Object::toString) .toArray(String[]::new); - } - else { + } else { choices = null; } - return choices; + return choices; } @Override - public String getKey() - { + public String getKey() { return key; } @Override - public Optional getDefault() - { + public Optional getDefault() { return defaultValue; } @Override - public boolean isRequired(Properties properties) - { + public boolean isRequired(Properties properties) { return isRequired.test(properties); } @Override - public boolean isAllowed(Properties properties) - { + public boolean isAllowed(Properties properties) { return isAllowed.test(properties); } @Override public Optional getValue(Properties properties) - throws SQLException - { + throws SQLException { String value = properties.getProperty(key); if (value == null) { if (isRequired(properties)) { @@ -187,8 +172,7 @@ public Optional getValue(Properties properties) try { return Optional.of(converter.convert(value)); - } - catch (RuntimeException e) { + } catch (RuntimeException e) { if (value.isEmpty()) { throw new SQLException(format("Connection property '%s' value is empty", key), e); } @@ -197,8 +181,7 @@ public Optional getValue(Properties properties) } @Override - public DriverPropertyInfo getDriverPropertyInfo(Properties mergedProperties) - { + public DriverPropertyInfo getDriverPropertyInfo(Properties mergedProperties) { String currentValue = mergedProperties.getProperty(key); DriverPropertyInfo result = new DriverPropertyInfo(key, currentValue); result.required = isRequired.test(mergedProperties); @@ -208,8 +191,7 @@ public DriverPropertyInfo getDriverPropertyInfo(Properties mergedProperties) @Override public void validate(Properties properties) - throws SQLException - { + throws SQLException { if (properties.containsKey(key) && !isAllowed(properties)) { throw new SQLException(format("Connection property '%s' is not allowed", key)); } @@ -217,13 +199,11 @@ public void validate(Properties properties) getValue(properties); } - interface Converter - { + interface Converter { T convert(String value); } - protected interface CheckedPredicate - { + protected interface CheckedPredicate { boolean test(T t) throws SQLException; } diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendClientLoadBalancingPolicy.java b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendClientLoadBalancingPolicy.java index 1f51b6f6..72feb8a6 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendClientLoadBalancingPolicy.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendClientLoadBalancingPolicy.java @@ -2,7 +2,6 @@ import java.net.URI; import java.util.List; -import java.util.Random; public class DatabendClientLoadBalancingPolicy { static class DisabledPolicy extends DatabendClientLoadBalancingPolicy { @@ -12,6 +11,7 @@ public String toString() { } // do nothing } + static class RandomPolicy extends DatabendClientLoadBalancingPolicy { @Override protected URI pickUri(String query_id, DatabendNodes nodes) { @@ -56,6 +56,7 @@ public String toString() { return "RoundRobin"; } } + /** * Policy that disable load balance and always use the first node. */ @@ -88,6 +89,7 @@ static DatabendClientLoadBalancingPolicy create(String name) { /** * Policy to pick a node based on the least loaded algorithm. + * * @param nodes the list of URIs to choose from * @return the URI to use */ @@ -101,6 +103,7 @@ protected URI pickUri(String query_id, DatabendNodes nodes) { /** * Get int hash value of given query id + * * @param query_id the query id used for choosing load balancing node * @return hash value of the query id */ diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendConnection.java b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendConnection.java index 48469483..5fde3d4c 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendConnection.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendConnection.java @@ -1,6 +1,12 @@ package com.databend.jdbc; -import com.databend.client.*; +import com.databend.client.ClientSettings; +import com.databend.client.DatabendClient; +import com.databend.client.DatabendClientV1; +import com.databend.client.DatabendSession; +import com.databend.client.PaginationOptions; +import com.databend.client.QueryRequest; +import com.databend.client.StageAttachment; import com.databend.jdbc.annotation.NotImplemented; import com.databend.jdbc.cloud.DatabendCopyParams; import com.databend.jdbc.cloud.DatabendPresignClient; @@ -9,10 +15,13 @@ import okhttp3.Headers; import okhttp3.OkHttpClient; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.net.ConnectException; import java.net.URI; -import java.net.URISyntaxException; import java.sql.Array; import java.sql.Blob; import java.sql.CallableStatement; @@ -30,15 +39,22 @@ import java.sql.Savepoint; import java.sql.Statement; import java.sql.Struct; -import java.util.*; +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.Random; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; -import java.util.logging.*; import java.util.function.Consumer; +import java.util.logging.FileHandler; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.logging.SimpleFormatter; import java.util.zip.GZIPOutputStream; import static com.databend.client.ClientSettings.*; @@ -145,7 +161,6 @@ public static URI parseRouteHint(String routeHint) { } - private static void checkResultSet(int resultSetType, int resultSetConcurrency) throws SQLFeatureNotSupportedException { if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) { @@ -660,6 +675,7 @@ public void accept(DatabendSession session) { /** * Retry executing a query in case of connection errors. fail over mechanism is used to retry the query when connect error occur * It will find next target host based on configured Load balancing Policy. + * * @param sql The SQL statement to execute. * @param attach The stage attachment to use for the query. * @return A DatabendClient instance representing the successful query execution. @@ -670,7 +686,7 @@ DatabendClient startQueryWithFailover(String sql, StageAttachment attach) throws Exception e = null; int times = getMaxFailoverRetries() + 1; - for( int i = 1; i <= times; i++) { + for (int i = 1; i <= times; i++) { if (e != null && !(e.getCause() instanceof ConnectException)) { throw new SQLException("Error start query: " + "SQL: " + sql + " " + e.getMessage() + " cause: " + e.getCause(), e); } @@ -712,7 +728,7 @@ DatabendClient startQueryWithFailover(String sql, StageAttachment attach) throws throw new SQLException("Error executing query: " + "SQL: " + sql + " " + e1.getMessage() + " cause: " + e1.getCause(), e1); } } - throw new SQLException("Failover Retry Error executing query after" + getMaxFailoverRetries() + "failover retry: " + "SQL: " + sql + " " + e.getMessage() + " cause: " + e.getCause(), e); + throw new SQLException("Failover Retry Error executing query after" + getMaxFailoverRetries() + "failover retry: " + "SQL: " + sql + " " + e.getMessage() + " cause: " + e.getCause(), e); } DatabendClient startQuery(String sql) throws SQLException { diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDatabaseMetaData.java b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDatabaseMetaData.java index 06618951..12ef87c7 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDatabaseMetaData.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDatabaseMetaData.java @@ -3,7 +3,6 @@ import com.databend.client.QueryRowField; import com.databend.client.data.DatabendDataType; import com.databend.client.data.DatabendRawType; -import com.databend.client.data.DatabendTypes; import com.google.common.base.Joiner; import java.sql.Connection; @@ -20,10 +19,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import static com.databend.jdbc.DriverInfo.DRIVER_NAME; -import static com.databend.jdbc.DriverInfo.DRIVER_VERSION; -import static com.databend.jdbc.DriverInfo.DRIVER_VERSION_MAJOR; -import static com.databend.jdbc.DriverInfo.DRIVER_VERSION_MINOR; +import static com.databend.jdbc.DriverInfo.*; import static java.util.Objects.requireNonNull; public class DatabendDatabaseMetaData implements DatabaseMetaData { @@ -1040,7 +1036,7 @@ public ResultSet getColumns(String catalog, String schemaPattern, String tableNa emptyStringLikeFilter(filters, "table_schema", schemaPattern); if (tableNamePattern != null) { optionalStringLikeFilter(filters, "table_name", tableNamePattern.replace("\\", "")); - }else { + } else { optionalStringLikeFilter(filters, "table_name", null); } optionalStringLikeFilter(filters, "column_name", columnNamePattern); diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDriver.java b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDriver.java index 3551a5e8..00030e1d 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDriver.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDriver.java @@ -5,13 +5,11 @@ import java.util.logging.Level; import java.util.logging.Logger; -public class DatabendDriver extends NonRegisteringDatabendDriver -{ +public class DatabendDriver extends NonRegisteringDatabendDriver { static { try { DriverManager.registerDriver(new DatabendDriver()); - } - catch (SQLException e) { + } catch (SQLException e) { Logger.getLogger(DatabendDriver.class.getPackage().getName()) .log(Level.SEVERE, "Failed to register driver", e); throw new RuntimeException("Failed to register DatabendDriver", e); diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDriverUri.java b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDriverUri.java index 8dc79017..864e8ea0 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDriverUri.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendDriverUri.java @@ -8,13 +8,21 @@ import java.net.URI; import java.net.URISyntaxException; import java.sql.SQLException; -import java.util.*; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Properties; +import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; -import static com.databend.client.OkHttpUtils.basicAuthInterceptor; -import static com.databend.client.OkHttpUtils.setupInsecureSsl; -import static com.databend.client.OkHttpUtils.tokenAuth; +import static com.databend.client.OkHttpUtils.*; import static com.databend.jdbc.ConnectionProperties.*; import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Strings.isNullOrEmpty; @@ -224,7 +232,7 @@ private static Map.Entry> parse(String url) try { for (String raw_host : hosts) { String fullUri = (raw_host.startsWith("http://") || raw_host.startsWith("https://")) ? - raw_host : + raw_host : "http://" + raw_host; URI uri = new URI(fullUri); @@ -306,6 +314,7 @@ public DatabendNodes getNodes() { public URI getUri() { return nodes.getUris().get(0); } + public URI getUri(String query_id) { return nodes.pickUri(query_id); } @@ -313,6 +322,7 @@ public URI getUri(String query_id) { public Boolean autoDiscovery() { return autoDiscovery; } + public String getDatabase() { return database; } diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendNodeRouter.java b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendNodeRouter.java index 386ac524..8e0d626e 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendNodeRouter.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendNodeRouter.java @@ -7,7 +7,7 @@ import java.util.List; /** - * Node manager manage a list of hosts + * Node manager manage a list of hosts */ public interface DatabendNodeRouter { /** @@ -24,6 +24,7 @@ public interface DatabendNodeRouter { /** * Discover all possible query uris through databend discovery api and update candidate node router list in need + * * @return true if update operation executed, false otherwise * Ref PR: * https://github.com/datafuselabs/databend-jdbc/pull/264 diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendNodes.java b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendNodes.java index 39a7cf07..9c5c96a1 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendNodes.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendNodes.java @@ -14,9 +14,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; -import static com.databend.jdbc.ConnectionProperties.SSL; -import static com.databend.jdbc.ConnectionProperties.SSL_MODE; - public class DatabendNodes implements DatabendNodeRouter { private AtomicReference> query_nodes_uris; @@ -95,7 +92,7 @@ private List parseURI(List nodes) throws SQLException { for (DiscoveryNode node : nodes) { String raw_host = node.getAddress(); String fullUri = (raw_host.startsWith("http://") || raw_host.startsWith("https://")) ? - raw_host : + raw_host : "http://" + raw_host; URI uri = new URI(fullUri); @@ -121,9 +118,11 @@ private List parseURI(List nodes) throws SQLException { return uris; } + public URI pickUri(String query_id) { return policy.pickUri(query_id, this); } + @Override public String toString() { return "DatabendNodes{" + diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendParameterMetaData.java b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendParameterMetaData.java index c1d23199..f7622a62 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendParameterMetaData.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendParameterMetaData.java @@ -5,7 +5,6 @@ import java.sql.Types; import java.util.List; import java.util.Locale; -import java.util.Map; import static com.databend.jdbc.DatabendResultSetMetaData.getTypeClassName; import static java.util.Objects.requireNonNull; diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendPreparedStatement.java b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendPreparedStatement.java index a21d02a4..13db41d8 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendPreparedStatement.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendPreparedStatement.java @@ -11,7 +11,13 @@ import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.ISODateTimeFormat; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; import java.math.BigDecimal; import java.net.URL; import java.nio.charset.StandardCharsets; @@ -35,24 +41,25 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; -import java.time.OffsetTime; import java.time.OffsetDateTime; +import java.time.OffsetTime; import java.time.format.DateTimeFormatterBuilder; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Base64; +import java.util.Calendar; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; import java.util.function.Consumer; import java.util.logging.Logger; import java.util.stream.Collectors; -import static com.databend.jdbc.ObjectCasts.castToBigDecimal; -import static com.databend.jdbc.ObjectCasts.castToBinary; -import static com.databend.jdbc.ObjectCasts.castToBoolean; -import static com.databend.jdbc.ObjectCasts.castToByte; -import static com.databend.jdbc.ObjectCasts.castToDouble; -import static com.databend.jdbc.ObjectCasts.castToFloat; -import static com.databend.jdbc.ObjectCasts.castToInt; -import static com.databend.jdbc.ObjectCasts.castToLong; -import static com.databend.jdbc.ObjectCasts.castToShort; +import static com.databend.jdbc.ObjectCasts.*; import static com.databend.jdbc.StatementUtil.replaceParameterMarksWithValues; import static java.lang.String.format; import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE; diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendResultSet.java b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendResultSet.java index 523703fc..fe235179 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendResultSet.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendResultSet.java @@ -9,7 +9,6 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder; import javax.annotation.concurrent.GuardedBy; - import java.sql.SQLException; import java.sql.Statement; import java.util.Iterator; diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendStatement.java b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendStatement.java index 129d8c37..0ee3bbe3 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendStatement.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendStatement.java @@ -1,6 +1,9 @@ package com.databend.jdbc; -import com.databend.client.*; +import com.databend.client.DatabendClient; +import com.databend.client.DatabendSession; +import com.databend.client.QueryResults; +import com.databend.client.StageAttachment; import com.databend.jdbc.annotation.NotImplemented; import java.sql.Connection; diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendUnboundQueryResultSet.java b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendUnboundQueryResultSet.java index 3eb1a942..306a3dc1 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/DatabendUnboundQueryResultSet.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/DatabendUnboundQueryResultSet.java @@ -1,6 +1,5 @@ package com.databend.jdbc; -import com.databend.client.DatabendClient; import com.databend.client.QueryRowField; import java.sql.SQLException; diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/DriverInfo.java b/databend-jdbc/src/main/java/com/databend/jdbc/DriverInfo.java index 9bcd26f8..15b1d86b 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/DriverInfo.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/DriverInfo.java @@ -16,14 +16,14 @@ import static com.google.common.io.Resources.getResource; import static java.lang.Integer.parseInt; -final class DriverInfo -{ +final class DriverInfo { static final String DRIVER_NAME; static final String DRIVER_VERSION; static final int DRIVER_VERSION_MAJOR; static final int DRIVER_VERSION_MINOR; - private DriverInfo() {} + private DriverInfo() { + } static { try { @@ -31,8 +31,7 @@ private DriverInfo() {} URL url = getResource(DriverInfo.class, "driver.properties"); try (InputStream in = url.openStream()) { properties.load(in); - } - catch (IOException e) { + } catch (IOException e) { throw new UncheckedIOException(e); } @@ -47,8 +46,7 @@ private DriverInfo() {} DRIVER_VERSION_MAJOR = parseInt(matcher.group(1)); DRIVER_VERSION_MINOR = parseInt(firstNonNull(matcher.group(3), "0")); - } - catch (RuntimeException e) { + } catch (RuntimeException e) { // log message since DriverManager hides initialization exceptions Logger.getLogger(DatabendDriver.class.getPackage().getName()) .log(Level.SEVERE, "Failed to load driver info", e); diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/JdbcTypeMapping.java b/databend-jdbc/src/main/java/com/databend/jdbc/JdbcTypeMapping.java index 09f0f052..82aa5430 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/JdbcTypeMapping.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/JdbcTypeMapping.java @@ -3,7 +3,6 @@ import com.databend.client.data.DatabendDataType; import java.sql.Types; -import java.util.Map; public class JdbcTypeMapping { /** diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/LoggerUtil.java b/databend-jdbc/src/main/java/com/databend/jdbc/LoggerUtil.java index 12725b0c..9c25f3e5 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/LoggerUtil.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/LoggerUtil.java @@ -1,16 +1,19 @@ package com.databend.jdbc; -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.util.stream.Collectors; - import com.databend.jdbc.log.DatabendLogger; import com.databend.jdbc.log.JDKLogger; import com.databend.jdbc.log.SLF4JLogger; - import lombok.CustomLog; import lombok.experimental.UtilityClass; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.stream.Collectors; + @UtilityClass @CustomLog public class LoggerUtil { diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/NonQueryRawStatement.java b/databend-jdbc/src/main/java/com/databend/jdbc/NonQueryRawStatement.java index 41d77e64..e6236740 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/NonQueryRawStatement.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/NonQueryRawStatement.java @@ -1,11 +1,10 @@ package com.databend.jdbc; -import static com.databend.jdbc.StatementType.NON_QUERY; +import lombok.EqualsAndHashCode; import java.util.List; - -import lombok.EqualsAndHashCode; +import static com.databend.jdbc.StatementType.NON_QUERY; /** * A non query statement is a statement that does not return data (such as diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/NonRegisteringDatabendDriver.java b/databend-jdbc/src/main/java/com/databend/jdbc/NonRegisteringDatabendDriver.java index 6fc900df..1e92be34 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/NonRegisteringDatabendDriver.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/NonRegisteringDatabendDriver.java @@ -3,7 +3,6 @@ import okhttp3.OkHttpClient; import java.io.Closeable; -import java.io.IOException; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverPropertyInfo; @@ -13,10 +12,7 @@ import java.util.logging.Logger; import static com.databend.client.OkHttpUtils.userAgentInterceptor; -import static com.databend.jdbc.DriverInfo.DRIVER_NAME; -import static com.databend.jdbc.DriverInfo.DRIVER_VERSION; -import static com.databend.jdbc.DriverInfo.DRIVER_VERSION_MAJOR; -import static com.databend.jdbc.DriverInfo.DRIVER_VERSION_MINOR; +import static com.databend.jdbc.DriverInfo.*; public class NonRegisteringDatabendDriver implements Driver, Closeable { private final OkHttpClient httpClient = newHttpClient(); diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/ObjectCasts.java b/databend-jdbc/src/main/java/com/databend/jdbc/ObjectCasts.java index 8069fed2..52ff9f24 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/ObjectCasts.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/ObjectCasts.java @@ -14,13 +14,12 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Locale.ENGLISH; -final class ObjectCasts -{ - private ObjectCasts() {} +final class ObjectCasts { + private ObjectCasts() { + } public static boolean castToBoolean(Object x, int targetSqlType) - throws SQLException - { + throws SQLException { if (x instanceof Boolean) { return (Boolean) x; } @@ -39,16 +38,14 @@ public static boolean castToBoolean(Object x, int targetSqlType) } throw new IllegalArgumentException("Invalid boolean value: " + x); } - } - catch (RuntimeException e) { + } catch (RuntimeException e) { throw invalidConversion(x, targetSqlType, e); } throw invalidConversion(x, targetSqlType); } public static byte castToByte(Object x, int targetSqlType) - throws SQLException - { + throws SQLException { if (x instanceof Boolean) { return (byte) (((Boolean) x) ? 1 : 0); } @@ -59,16 +56,14 @@ public static byte castToByte(Object x, int targetSqlType) if (x instanceof String) { return parseByte((String) x); } - } - catch (RuntimeException e) { + } catch (RuntimeException e) { throw invalidConversion(x, targetSqlType, e); } throw invalidConversion(x, targetSqlType); } public static short castToShort(Object x, int targetSqlType) - throws SQLException - { + throws SQLException { if (x instanceof Boolean) { return (short) (((Boolean) x) ? 1 : 0); } @@ -79,16 +74,14 @@ public static short castToShort(Object x, int targetSqlType) if (x instanceof String) { return parseShort((String) x); } - } - catch (RuntimeException e) { + } catch (RuntimeException e) { throw invalidConversion(x, targetSqlType, e); } throw invalidConversion(x, targetSqlType); } public static int castToInt(Object x, int targetSqlType) - throws SQLException - { + throws SQLException { if (x instanceof Boolean) { return (((Boolean) x) ? 1 : 0); } @@ -99,16 +92,14 @@ public static int castToInt(Object x, int targetSqlType) if (x instanceof String) { return parseInt((String) x); } - } - catch (RuntimeException e) { + } catch (RuntimeException e) { throw invalidConversion(x, targetSqlType, e); } throw invalidConversion(x, targetSqlType); } public static long castToLong(Object x, int targetSqlType) - throws SQLException - { + throws SQLException { if (x instanceof Boolean) { return (((Boolean) x) ? 1 : 0); } @@ -119,16 +110,14 @@ public static long castToLong(Object x, int targetSqlType) if (x instanceof String) { return parseLong((String) x); } - } - catch (RuntimeException e) { + } catch (RuntimeException e) { throw invalidConversion(x, targetSqlType, e); } throw invalidConversion(x, targetSqlType); } public static float castToFloat(Object x, int targetSqlType) - throws SQLException - { + throws SQLException { if (x instanceof Boolean) { return (((Boolean) x) ? 1 : 0); } @@ -139,16 +128,14 @@ public static float castToFloat(Object x, int targetSqlType) if (x instanceof String) { return parseFloat((String) x); } - } - catch (RuntimeException e) { + } catch (RuntimeException e) { throw invalidConversion(x, targetSqlType, e); } throw invalidConversion(x, targetSqlType); } public static double castToDouble(Object x, int targetSqlType) - throws SQLException - { + throws SQLException { if (x instanceof Boolean) { return (((Boolean) x) ? 1 : 0); } @@ -159,16 +146,14 @@ public static double castToDouble(Object x, int targetSqlType) if (x instanceof String) { return parseDouble((String) x); } - } - catch (RuntimeException e) { + } catch (RuntimeException e) { throw invalidConversion(x, targetSqlType, e); } throw invalidConversion(x, targetSqlType); } public static BigDecimal castToBigDecimal(Object x, int targetSqlType) - throws SQLException - { + throws SQLException { if (x instanceof Boolean) { return BigDecimal.valueOf(((Boolean) x) ? 1 : 0); } @@ -188,16 +173,14 @@ public static BigDecimal castToBigDecimal(Object x, int targetSqlType) if (x instanceof String) { return new BigDecimal((String) x); } - } - catch (RuntimeException e) { + } catch (RuntimeException e) { throw invalidConversion(x, targetSqlType, e); } throw invalidConversion(x, targetSqlType); } public static byte[] castToBinary(Object x, int targetSqlType) - throws SQLException - { + throws SQLException { if (x instanceof byte[]) { return (byte[]) x; } @@ -207,18 +190,15 @@ public static byte[] castToBinary(Object x, int targetSqlType) throw invalidConversion(x, targetSqlType); } - private static SQLException invalidConversion(Object x, int sqlType) - { + private static SQLException invalidConversion(Object x, int sqlType) { return invalidConversion(x, sqlType, null); } - private static SQLException invalidConversion(Object x, int sqlType, Exception e) - { + private static SQLException invalidConversion(Object x, int sqlType, Exception e) { return new SQLException(format("Cannot convert instance of %s to SQL type %s", x.getClass().getName(), sqlType), e); } - static SQLException invalidConversion(Object x, String toType) - { + static SQLException invalidConversion(Object x, String toType) { return new SQLException(format("Cannot convert instance of %s to %s", x.getClass().getName(), toType)); } } diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/ParamMarker.java b/databend-jdbc/src/main/java/com/databend/jdbc/ParamMarker.java index b1266669..92e707ec 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/ParamMarker.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/ParamMarker.java @@ -1,4 +1,5 @@ package com.databend.jdbc; + import lombok.AllArgsConstructor; import lombok.Value; diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/PresignContext.java b/databend-jdbc/src/main/java/com/databend/jdbc/PresignContext.java index 2a69ff07..406b8c96 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/PresignContext.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/PresignContext.java @@ -40,7 +40,7 @@ public static void dropStageIfExists(DatabendConnection connection, String stage } public static PresignContext getPresignContext(DatabendConnection connection, PresignMethod method, String stageName, String fileName) - throws SQLException { + throws SQLException { requireNonNull(connection, "connection is null"); requireNonNull(method, "method is null"); Statement statement = connection.createStatement(); diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/QueryRawStatement.java b/databend-jdbc/src/main/java/com/databend/jdbc/QueryRawStatement.java index a6b22c4d..aefab2e6 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/QueryRawStatement.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/QueryRawStatement.java @@ -1,15 +1,13 @@ package com.databend.jdbc; -import static com.databend.jdbc.StatementType.QUERY; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import org.apache.commons.lang3.tuple.Pair; import java.util.List; import java.util.Optional; -import org.apache.commons.lang3.tuple.Pair; - - -import lombok.EqualsAndHashCode; -import lombok.Getter; +import static com.databend.jdbc.StatementType.QUERY; /** * A query statement is a statement that returns data (Typically starts with diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/RawStatement.java b/databend-jdbc/src/main/java/com/databend/jdbc/RawStatement.java index 68a68b88..15719c1e 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/RawStatement.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/RawStatement.java @@ -1,15 +1,11 @@ package com.databend.jdbc; -import java.util.List; -import java.util.Optional; - +import lombok.Data; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; -import com.databend.jdbc.ParamMarker; -import com.databend.jdbc.StatementType; - -import lombok.Data; +import java.util.List; +import java.util.Optional; @Data public abstract class RawStatement { diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/RawStatementWrapper.java b/databend-jdbc/src/main/java/com/databend/jdbc/RawStatementWrapper.java index fdca4c4a..d74d8908 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/RawStatementWrapper.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/RawStatementWrapper.java @@ -1,11 +1,11 @@ package com.databend.jdbc; -import java.util.Collection; -import java.util.List; - -import org.apache.commons.lang3.StringUtils; import lombok.CustomLog; import lombok.Value; +import org.apache.commons.lang3.StringUtils; + +import java.util.Collection; +import java.util.List; @CustomLog @Value diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/SetParamRawStatement.java b/databend-jdbc/src/main/java/com/databend/jdbc/SetParamRawStatement.java index 2e230319..4b72e45a 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/SetParamRawStatement.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/SetParamRawStatement.java @@ -1,12 +1,12 @@ package com.databend.jdbc; -import static com.databend.jdbc.StatementType.PARAM_SETTING; - -import java.util.List; - -import org.apache.commons.lang3.tuple.Pair; import lombok.EqualsAndHashCode; import lombok.Getter; +import org.apache.commons.lang3.tuple.Pair; + +import java.util.List; + +import static com.databend.jdbc.StatementType.PARAM_SETTING; /** * A Set param statement is a special statement that sets a parameter internally diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/StatementInfoWrapper.java b/databend-jdbc/src/main/java/com/databend/jdbc/StatementInfoWrapper.java index 7f88beb4..5814b119 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/StatementInfoWrapper.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/StatementInfoWrapper.java @@ -1,16 +1,14 @@ package com.databend.jdbc; -import static com.databend.jdbc.StatementType.PARAM_SETTING; - -import java.util.UUID; - -import org.apache.commons.lang3.tuple.Pair; - - import lombok.AllArgsConstructor; import lombok.Data; import lombok.NonNull; +import org.apache.commons.lang3.tuple.Pair; + +import java.util.UUID; + +import static com.databend.jdbc.StatementType.PARAM_SETTING; /** * This represents a statement that is ready to be sent to Databend or executed @@ -39,7 +37,7 @@ public static StatementInfoWrapper of(@NonNull RawStatement rawStatement) { * Creates a StatementInfoWrapper from the {@link RawStatement}. * * @param rawStatement the raw statement - * @param id the id of the statement to execute + * @param id the id of the statement to execute * @return the statement that will be sent to the server */ public static StatementInfoWrapper of(@NonNull RawStatement rawStatement, String id) { diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/StatementType.java b/databend-jdbc/src/main/java/com/databend/jdbc/StatementType.java index 3eff1f3f..cde09627 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/StatementType.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/StatementType.java @@ -1,4 +1,5 @@ package com.databend.jdbc; + public enum StatementType { PARAM_SETTING, // SET QUERY, // eg: SELECT, SHOW diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/StatementUtil.java b/databend-jdbc/src/main/java/com/databend/jdbc/StatementUtil.java index a4680ba7..8f80f9a9 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/StatementUtil.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/StatementUtil.java @@ -1,18 +1,23 @@ package com.databend.jdbc; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - +import lombok.CustomLog; +import lombok.NonNull; +import lombok.experimental.UtilityClass; import org.apache.commons.lang3.RegExUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; -import lombok.CustomLog; -import lombok.NonNull; -import lombok.experimental.UtilityClass; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; @UtilityClass @CustomLog diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/cloud/DatabendCopyParams.java b/databend-jdbc/src/main/java/com/databend/jdbc/cloud/DatabendCopyParams.java index cde8e097..04ca87e1 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/cloud/DatabendCopyParams.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/cloud/DatabendCopyParams.java @@ -1,6 +1,5 @@ package com.databend.jdbc.cloud; -import javax.xml.crypto.Data; import java.util.List; import java.util.Locale; import java.util.Map; diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/cloud/DatabendPresignClientV1.java b/databend-jdbc/src/main/java/com/databend/jdbc/cloud/DatabendPresignClientV1.java index 7e65c9de..81204b62 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/cloud/DatabendPresignClientV1.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/cloud/DatabendPresignClientV1.java @@ -1,6 +1,5 @@ package com.databend.jdbc.cloud; -import com.databend.client.DatabendClientV1; import okhttp3.Headers; import okhttp3.HttpUrl; import okhttp3.MediaType; @@ -16,7 +15,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; import javax.annotation.Nullable; - import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -27,7 +25,6 @@ import java.util.logging.Level; import java.util.logging.Logger; -import static com.databend.jdbc.ConnectionProperties.SOCKET_TIMEOUT; import static java.lang.String.format; import static java.util.Objects.requireNonNull; import static java.util.concurrent.TimeUnit.MILLISECONDS; diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/cloud/DatabendStage.java b/databend-jdbc/src/main/java/com/databend/jdbc/cloud/DatabendStage.java index 966dcc45..876950a1 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/cloud/DatabendStage.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/cloud/DatabendStage.java @@ -1,46 +1,40 @@ package com.databend.jdbc.cloud; -public class DatabendStage -{ +public class DatabendStage { private static final String defaultStageName = "~"; private final String stageName; private final String path; private final ExternalLocationS3 externalLocationS3; + // TODO(zhihanz) support more external location such as Azure/GCS - private DatabendStage(String stageName, String path, ExternalLocationS3 externalLocationS3) - { + private DatabendStage(String stageName, String path, ExternalLocationS3 externalLocationS3) { if (stageName == null || stageName.isEmpty()) { - this.stageName = defaultStageName; + this.stageName = defaultStageName; } else { - this.stageName = stageName; + this.stageName = stageName; } this.path = path; this.externalLocationS3 = externalLocationS3; } - public static DatabendStage.Builder builder() - { + public static DatabendStage.Builder builder() { return new DatabendStage.Builder(); } - public String getStageName() - { + public String getStageName() { return stageName; } - public String getPath() - { + public String getPath() { return path; } - public ExternalLocationS3 getExternalLocationS3() - { + public ExternalLocationS3 getExternalLocationS3() { return externalLocationS3; } @Override - public String toString() - { + public String toString() { if (this.externalLocationS3 != null) { return this.externalLocationS3.toString(); } @@ -51,32 +45,27 @@ public String toString() } - public static class Builder - { + public static class Builder { private String stageName; private String path; private ExternalLocationS3 externalLocationS3; - public Builder stageName(String stageName) - { + public Builder stageName(String stageName) { this.stageName = stageName; return this; } - public Builder path(String path) - { + public Builder path(String path) { this.path = path; return this; } - public Builder externalLocationS3(ExternalLocationS3 externalLocationS3) - { + public Builder externalLocationS3(ExternalLocationS3 externalLocationS3) { this.externalLocationS3 = externalLocationS3; return this; } - public DatabendStage build() - { + public DatabendStage build() { return new DatabendStage(stageName, path, externalLocationS3); } } diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/cloud/ExternalLocationS3.java b/databend-jdbc/src/main/java/com/databend/jdbc/cloud/ExternalLocationS3.java index c7fba93d..8b41696f 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/cloud/ExternalLocationS3.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/cloud/ExternalLocationS3.java @@ -1,8 +1,7 @@ package com.databend.jdbc.cloud; // https://databend.rs/doc/sql-commands/dml/dml-copy-into-table#externallocation -public class ExternalLocationS3 -{ +public class ExternalLocationS3 { // for example: s3://bucket_name/path private final String location; private final String endpointUrl; @@ -11,8 +10,8 @@ public class ExternalLocationS3 private final String sessionToken; private final String region; private final boolean enableVirtualHostStyle; - private ExternalLocationS3(String location, String endpointUrl, String accessKeyId, String secretAccessKey, String sessionToken, String region, boolean enableVirtualHostStyle) - { + + private ExternalLocationS3(String location, String endpointUrl, String accessKeyId, String secretAccessKey, String sessionToken, String region, boolean enableVirtualHostStyle) { this.location = location; this.endpointUrl = endpointUrl; this.accessKeyId = accessKeyId; @@ -26,38 +25,31 @@ public static ExternalLocationS3.Builder builder() { return new ExternalLocationS3.Builder(); } - public String getLocation() - { + public String getLocation() { return location; } - public String getEndpointUrl() - { + public String getEndpointUrl() { return endpointUrl; } - public String getAccessKeyId() - { + public String getAccessKeyId() { return accessKeyId; } - public String getSecretAccessKey() - { + public String getSecretAccessKey() { return secretAccessKey; } - public String getSessionToken() - { + public String getSessionToken() { return sessionToken; } - public String getRegion() - { + public String getRegion() { return region; } - public boolean isEnableVirtualHostStyle() - { + public boolean isEnableVirtualHostStyle() { return enableVirtualHostStyle; } @@ -112,8 +104,7 @@ public String toString() { } // builder pattern - public static class Builder - { + public static class Builder { private String location; private String endpointUrl; private String accessKeyId; @@ -122,50 +113,42 @@ public static class Builder private String region; private boolean enableVirtualHostStyle; - public Builder setLocation(String location) - { + public Builder setLocation(String location) { this.location = location; return this; } - public Builder setEndpointUrl(String endpointUrl) - { + public Builder setEndpointUrl(String endpointUrl) { this.endpointUrl = endpointUrl; return this; } - public Builder setAccessKeyId(String accessKeyId) - { + public Builder setAccessKeyId(String accessKeyId) { this.accessKeyId = accessKeyId; return this; } - public Builder setSecretAccessKey(String secretAccessKey) - { + public Builder setSecretAccessKey(String secretAccessKey) { this.secretAccessKey = secretAccessKey; return this; } - public Builder setSessionToken(String sessionToken) - { + public Builder setSessionToken(String sessionToken) { this.sessionToken = sessionToken; return this; } - public Builder setRegion(String region) - { + public Builder setRegion(String region) { this.region = region; return this; } - public Builder setEnableVirtualHostStyle(boolean enableVirtualHostStyle) - { + public Builder setEnableVirtualHostStyle(boolean enableVirtualHostStyle) { this.enableVirtualHostStyle = enableVirtualHostStyle; return this; } - public ExternalLocationS3 build() - { + public ExternalLocationS3 build() { return new ExternalLocationS3(location, endpointUrl, accessKeyId, secretAccessKey, sessionToken, region, enableVirtualHostStyle); } } diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/examples/DatabendConnectionFactory.java b/databend-jdbc/src/main/java/com/databend/jdbc/examples/DatabendConnectionFactory.java index 466f315b..2bfd1ffd 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/examples/DatabendConnectionFactory.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/examples/DatabendConnectionFactory.java @@ -1,10 +1,9 @@ package com.databend.jdbc.examples; + import com.databend.jdbc.DatabendConnection; -import com.fasterxml.jackson.databind.annotation.JsonAppend; -import org.apache.commons.pool2.PooledObjectFactory; import org.apache.commons.pool2.PooledObject; +import org.apache.commons.pool2.PooledObjectFactory; import org.apache.commons.pool2.impl.DefaultPooledObject; -import org.apache.commons.pool2.impl.GenericObjectPool; import java.sql.Connection; import java.sql.DriverManager; @@ -13,13 +12,14 @@ public class DatabendConnectionFactory implements PooledObjectFactory { - private String url; + private String url; private Properties properties; public DatabendConnectionFactory(String url, Properties properties) { this.url = url; this.properties = properties; } + private Connection createConnection(String url, Properties p) throws SQLException { return DriverManager.getConnection(url, p); } diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/examples/DatabendConnectionPool.java b/databend-jdbc/src/main/java/com/databend/jdbc/examples/DatabendConnectionPool.java index 77954622..9ec68768 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/examples/DatabendConnectionPool.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/examples/DatabendConnectionPool.java @@ -8,7 +8,7 @@ public class DatabendConnectionPool extends GenericObjectPool { public DatabendConnectionPool(DatabendConnectionFactory factory, GenericObjectPoolConfig config) { - super(factory,config); + super(factory, config); } public void testDemo() throws Exception { @@ -21,7 +21,7 @@ public void testDemo() throws Exception { props.setProperty("SSL", "false"); // Create a Databend connection pool DatabendConnectionFactory factory = new DatabendConnectionFactory("jdbc:databend://localhost:8000", props); - DatabendConnectionPool pool = new DatabendConnectionPool(factory,config); + DatabendConnectionPool pool = new DatabendConnectionPool(factory, config); // Get a connection from the pool DatabendConnection connection = pool.borrowObject(); diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/examples/Examples.java b/databend-jdbc/src/main/java/com/databend/jdbc/examples/Examples.java index f23c87f8..40014ee4 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/examples/Examples.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/examples/Examples.java @@ -1,15 +1,10 @@ package com.databend.jdbc.examples; import java.sql.Connection; -import java.sql.Date; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.Statement; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.List; class Examples { private static Connection createConnection() diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/log/DatabendLogger.java b/databend-jdbc/src/main/java/com/databend/jdbc/log/DatabendLogger.java index 1ce7a2a4..688a6ef5 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/log/DatabendLogger.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/log/DatabendLogger.java @@ -2,34 +2,34 @@ public interface DatabendLogger { - void trace(String message); + void trace(String message); - void trace(String message, Object... arguments); + void trace(String message, Object... arguments); - void trace(String message, Throwable t); + void trace(String message, Throwable t); - void debug(String message); + void debug(String message); - void debug(String message, Object... arguments); + void debug(String message, Object... arguments); - void debug(String message, Throwable t); + void debug(String message, Throwable t); - void info(String message); + void info(String message); - void info(String message, Object... arguments); + void info(String message, Object... arguments); - void info(String message, Throwable t); + void info(String message, Throwable t); - void warn(String message); + void warn(String message); - void warn(String message, Object... arguments); + void warn(String message, Object... arguments); - void warn(String message, Throwable t); + void warn(String message, Throwable t); - void error(String message); + void error(String message); - void error(String message, Object... arguments); + void error(String message, Object... arguments); - void error(String message, Throwable t); + void error(String message, Throwable t); } diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/log/JDKLogger.java b/databend-jdbc/src/main/java/com/databend/jdbc/log/JDKLogger.java index 4ae6000e..6c3fe47e 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/log/JDKLogger.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/log/JDKLogger.java @@ -4,108 +4,108 @@ public class JDKLogger implements DatabendLogger { - private final java.util.logging.Logger logger; - - public JDKLogger(String name) { - this.logger = java.util.logging.Logger.getLogger(name); - } - - @Override - public void trace(String message) { - logger.log(Level.FINEST, message); - } - - @Override - public void trace(String message, Object... arguments) { - logger.log(Level.FINEST, addMissingArgumentsIndexes(message), arguments); - } - - @Override - public void trace(String message, Throwable t) { - logger.log(Level.FINEST, message, t); - } - - @Override - public void debug(String message) { - logger.log(Level.FINE, message); - } - - @Override - public void debug(String message, Object... arguments) { - logger.log(Level.FINE, addMissingArgumentsIndexes(message), arguments); - } - - @Override - public void debug(String message, Throwable t) { - logger.log(Level.FINE, message, t); - } - - @Override - public void info(String message) { - logger.log(Level.INFO, message); - } - - @Override - public void info(String message, Object... arguments) { - logger.log(Level.INFO, addMissingArgumentsIndexes(message), arguments); - } - - @Override - public void info(String message, Throwable t) { - logger.log(Level.INFO, message, t); - } - - @Override - public void warn(String message) { - logger.log(Level.WARNING, message); - } - - @Override - public void warn(String message, Object... arguments) { - logger.log(Level.WARNING, addMissingArgumentsIndexes(message), arguments); - } - - @Override - public void warn(String message, Throwable t) { - logger.log(Level.WARNING, message, t); - - } - - @Override - public void error(String message) { - logger.log(Level.SEVERE, message); - } - - @Override - public void error(String message, Object... arguments) { - logger.log(Level.SEVERE, addMissingArgumentsIndexes(message), arguments); - } - - @Override - public void error(String message, Throwable t) { - logger.log(Level.SEVERE, message, t); - } - - /** - * SLF4J and java.util.logging use a different log format. With SLF4J it is not - * required to have argument indexes in the logs (eg: "log.info("hello {}", - * "world");), but it is required for java.util.logging (eg: "log.info("hello - * {1}", "world");) In this project we use the SLF4J way of logging, which is - * why we need to add the missing indexes. - */ - private String addMissingArgumentsIndexes(String message) { - StringBuilder result = new StringBuilder(); - int argumentIndex = 0; - int i = 0; - while (i < message.length()) { - if (message.charAt(i) == '{' && i < message.length() - 1 && message.charAt(i + 1) == '}') { - result.append(String.format("{%d}", argumentIndex++)); - i++; - } else { - result.append(message.charAt(i)); - } - i++; - } - return result.toString(); - } + private final java.util.logging.Logger logger; + + public JDKLogger(String name) { + this.logger = java.util.logging.Logger.getLogger(name); + } + + @Override + public void trace(String message) { + logger.log(Level.FINEST, message); + } + + @Override + public void trace(String message, Object... arguments) { + logger.log(Level.FINEST, addMissingArgumentsIndexes(message), arguments); + } + + @Override + public void trace(String message, Throwable t) { + logger.log(Level.FINEST, message, t); + } + + @Override + public void debug(String message) { + logger.log(Level.FINE, message); + } + + @Override + public void debug(String message, Object... arguments) { + logger.log(Level.FINE, addMissingArgumentsIndexes(message), arguments); + } + + @Override + public void debug(String message, Throwable t) { + logger.log(Level.FINE, message, t); + } + + @Override + public void info(String message) { + logger.log(Level.INFO, message); + } + + @Override + public void info(String message, Object... arguments) { + logger.log(Level.INFO, addMissingArgumentsIndexes(message), arguments); + } + + @Override + public void info(String message, Throwable t) { + logger.log(Level.INFO, message, t); + } + + @Override + public void warn(String message) { + logger.log(Level.WARNING, message); + } + + @Override + public void warn(String message, Object... arguments) { + logger.log(Level.WARNING, addMissingArgumentsIndexes(message), arguments); + } + + @Override + public void warn(String message, Throwable t) { + logger.log(Level.WARNING, message, t); + + } + + @Override + public void error(String message) { + logger.log(Level.SEVERE, message); + } + + @Override + public void error(String message, Object... arguments) { + logger.log(Level.SEVERE, addMissingArgumentsIndexes(message), arguments); + } + + @Override + public void error(String message, Throwable t) { + logger.log(Level.SEVERE, message, t); + } + + /** + * SLF4J and java.util.logging use a different log format. With SLF4J it is not + * required to have argument indexes in the logs (eg: "log.info("hello {}", + * "world");), but it is required for java.util.logging (eg: "log.info("hello + * {1}", "world");) In this project we use the SLF4J way of logging, which is + * why we need to add the missing indexes. + */ + private String addMissingArgumentsIndexes(String message) { + StringBuilder result = new StringBuilder(); + int argumentIndex = 0; + int i = 0; + while (i < message.length()) { + if (message.charAt(i) == '{' && i < message.length() - 1 && message.charAt(i + 1) == '}') { + result.append(String.format("{%d}", argumentIndex++)); + i++; + } else { + result.append(message.charAt(i)); + } + i++; + } + return result.toString(); + } } diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/log/SLF4JLogger.java b/databend-jdbc/src/main/java/com/databend/jdbc/log/SLF4JLogger.java index 9876f869..7abe8bcc 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/log/SLF4JLogger.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/log/SLF4JLogger.java @@ -5,85 +5,85 @@ public class SLF4JLogger implements DatabendLogger { - private final Logger logger; - - public SLF4JLogger(String name) { - logger = LoggerFactory.getLogger(name); - } - - @Override - public void trace(String message) { - logger.trace(message); - } - - @Override - public void trace(String message, Object... arguments) { - logger.trace(message, arguments); - } - - @Override - public void trace(String message, Throwable t) { - logger.trace(message, t); - } - - @Override - public void debug(String message) { - logger.debug(message); - } - - @Override - public void debug(String message, Object... arguments) { - logger.debug(message, arguments); - - } - - @Override - public void debug(String message, Throwable t) { - logger.debug(message, t); - } - - @Override - public void info(String message) { - logger.info(message); - } - - @Override - public void info(String message, Object... arguments) { - logger.info(message, arguments); - } - - @Override - public void info(String message, Throwable t) { - logger.info(message, t); - } - - @Override - public void warn(String message) { - logger.warn(message); - } - - @Override - public void warn(String message, Object... arguments) { - logger.warn(message, arguments); - } - - @Override - public void warn(String message, Throwable t) { - logger.warn(message, t); - } - - @Override - public void error(String message) { - logger.error(message); - } - - @Override - public void error(String message, Object... arguments) { - logger.error(message, arguments); - } - - @Override - public void error(String message, Throwable t) { - logger.error(message, t); - } + private final Logger logger; + + public SLF4JLogger(String name) { + logger = LoggerFactory.getLogger(name); + } + + @Override + public void trace(String message) { + logger.trace(message); + } + + @Override + public void trace(String message, Object... arguments) { + logger.trace(message, arguments); + } + + @Override + public void trace(String message, Throwable t) { + logger.trace(message, t); + } + + @Override + public void debug(String message) { + logger.debug(message); + } + + @Override + public void debug(String message, Object... arguments) { + logger.debug(message, arguments); + + } + + @Override + public void debug(String message, Throwable t) { + logger.debug(message, t); + } + + @Override + public void info(String message) { + logger.info(message); + } + + @Override + public void info(String message, Object... arguments) { + logger.info(message, arguments); + } + + @Override + public void info(String message, Throwable t) { + logger.info(message, t); + } + + @Override + public void warn(String message) { + logger.warn(message); + } + + @Override + public void warn(String message, Object... arguments) { + logger.warn(message, arguments); + } + + @Override + public void warn(String message, Throwable t) { + logger.warn(message, t); + } + + @Override + public void error(String message) { + logger.error(message); + } + + @Override + public void error(String message, Object... arguments) { + logger.error(message, arguments); + } + + @Override + public void error(String message, Throwable t) { + logger.error(message, t); + } } diff --git a/databend-jdbc/src/main/java/com/databend/jdbc/parser/BatchInsertUtils.java b/databend-jdbc/src/main/java/com/databend/jdbc/parser/BatchInsertUtils.java index fe7f2dd6..835027e7 100644 --- a/databend-jdbc/src/main/java/com/databend/jdbc/parser/BatchInsertUtils.java +++ b/databend-jdbc/src/main/java/com/databend/jdbc/parser/BatchInsertUtils.java @@ -2,7 +2,6 @@ import de.siegmar.fastcsv.writer.CsvWriter; import de.siegmar.fastcsv.writer.LineDelimiter; -import de.siegmar.fastcsv.writer.QuoteStrategy; import java.io.File; import java.io.FileWriter; @@ -12,12 +11,11 @@ import java.util.Optional; import java.util.TreeMap; import java.util.UUID; -import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; -import java.util.stream.Stream; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class BatchInsertUtils { private static final Logger logger = Logger.getLogger(BatchInsertUtils.class.getPackage().getName()); diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/StatementUtilTest.java b/databend-jdbc/src/test/java/com/databend/jdbc/StatementUtilTest.java index dc7af752..9a91ae52 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/StatementUtilTest.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/StatementUtilTest.java @@ -1,13 +1,13 @@ package com.databend.jdbc; import com.google.common.collect.ImmutableMap; -import org.apache.commons.lang3.tuple.ImmutablePair; import org.junit.jupiter.api.Test; import java.util.Map; import static com.databend.jdbc.StatementUtil.replaceParameterMarksWithValues; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class StatementUtilTest { @Test void shouldGetAllQueryParamsFromIn() { @@ -16,6 +16,7 @@ void shouldGetAllQueryParamsFromIn() { System.out.println(StatementUtil.parseToRawStatementWrapper(sql).getSubStatements()); assertEquals(1, StatementUtil.parseToRawStatementWrapper(sql).getSubStatements().size()); } + @Test void shouldGetAllQueryParams() { String sql = "SElECT * FROM EMPLOYEES WHERE id = ?"; diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/TestBasicDriver.java b/databend-jdbc/src/test/java/com/databend/jdbc/TestBasicDriver.java index c8758e6d..d247017f 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/TestBasicDriver.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/TestBasicDriver.java @@ -8,8 +8,15 @@ import org.testng.Assert; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import org.junit.Ignore; -import java.sql.*; + +import java.sql.Connection; +import java.sql.Date; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Timestamp; import java.util.Properties; import static org.junit.jupiter.api.Assertions.assertThrows; diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/TestCopyInto.java b/databend-jdbc/src/test/java/com/databend/jdbc/TestCopyInto.java index dba09e4e..6fa004d8 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/TestCopyInto.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/TestCopyInto.java @@ -9,11 +9,9 @@ import static org.testng.Assert.assertEquals; -public class TestCopyInto -{ +public class TestCopyInto { @Test(groups = {"Unit"}) - public void TestParseSql() - { + public void TestParseSql() { DatabendStage s = DatabendStage.builder().stageName("~").path("a/b/c").build(); List files = new ArrayList<>(); files.add("file.csv"); diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDatabaseMetaData.java b/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDatabaseMetaData.java index 53ac3cc9..8e174219 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDatabaseMetaData.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDatabaseMetaData.java @@ -18,6 +18,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; + @Test(timeOut = 10000) public class TestDatabendDatabaseMetaData { private static void assertTableMetadata(ResultSet rs) @@ -99,7 +100,7 @@ public void testGetDatabaseProductVersion() throws Exception { try (Connection connection = createConnection()) { DatabaseMetaData metaData = connection.getMetaData(); - float majorVersion = (float)metaData.getDatabaseMajorVersion() / 10; + float majorVersion = (float) metaData.getDatabaseMajorVersion() / 10; int minorVersion = metaData.getDatabaseMinorVersion(); String checkVersion = String.format("v%.1f.%d", majorVersion, minorVersion); Assert.assertTrue(metaData.getDatabaseProductVersion().contains(checkVersion)); @@ -178,7 +179,7 @@ public void testColumnsMeta() throws Exception { String columnName = rs.getString("COLUMN_NAME"); int dataType = rs.getInt("data_type"); String columnType = rs.getString("type_name"); - System.out.println(tableCat + " "+tableSchem + " " + tableName + " " + columnName + " " + dataType + " " + columnType); + System.out.println(tableCat + " " + tableSchem + " " + tableName + " " + columnName + " " + dataType + " " + columnType); } } System.out.println("===================================="); @@ -229,7 +230,7 @@ public void testGetObjectWithDecimal() throws Exception { try (Connection connection = createConnection()) { connection.createStatement().execute("insert into decimal_test values(1.2)"); ResultSet rs = connection.createStatement().executeQuery("select * from decimal_test"); - while (rs.next()){ + while (rs.next()) { assertTrue(rs.getObject(1) instanceof BigDecimal); } } diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDriverUri.java b/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDriverUri.java index 926a9ca7..4477dc1c 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDriverUri.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendDriverUri.java @@ -9,6 +9,7 @@ import java.util.Properties; import static org.assertj.core.api.Assertions.assertThatThrownBy; + @Test(timeOut = 10000) public class TestDatabendDriverUri { private static DatabendDriverUri createDriverUri(String url) @@ -232,6 +233,7 @@ public void testFull() throws SQLException { Assert.assertEquals("null", uri.nullDisplay().toString()); Assert.assertEquals(false, uri.getStrNullAsNull()); } + @Test public void TestSetSchema() throws SQLException { String url = "jdbc:databend://databend:databend@localhost:8000/"; @@ -240,7 +242,7 @@ public void TestSetSchema() throws SQLException { try { connection.createStatement().execute("create or replace database test2"); connection.createStatement().execute("create or replace table test2.test2(id int)"); - }catch (SQLException e){ + } catch (SQLException e) { throw new RuntimeException(e); } connection.setSchema("test2"); diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendParameterMetaData.java b/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendParameterMetaData.java index e241c062..3f62d924 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendParameterMetaData.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/TestDatabendParameterMetaData.java @@ -5,8 +5,12 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import java.sql.*; -import java.util.Properties; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ParameterMetaData; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.Types; public class TestDatabendParameterMetaData { diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/TestFileTransfer.java b/databend-jdbc/src/test/java/com/databend/jdbc/TestFileTransfer.java index a29adba6..4a9bed0f 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/TestFileTransfer.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/TestFileTransfer.java @@ -21,8 +21,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.HashMap; -import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/TestMultiHost.java b/databend-jdbc/src/test/java/com/databend/jdbc/TestMultiHost.java index 06f2d5f1..d9b569ce 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/TestMultiHost.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/TestMultiHost.java @@ -1,6 +1,5 @@ package com.databend.jdbc; -import com.databend.client.PaginationOptions; import org.testng.Assert; import org.testng.annotations.Test; @@ -10,10 +9,11 @@ import java.sql.SQLException; public class TestMultiHost { - private final String DEFAULT_JDBC_URL = "jdbc:databend://localhost:8000,localhost:8002,localhost:8003/default"; - private final String RANDOM_JDBC_URL = "jdbc:databend://localhost:8000,localhost:8002,localhost:8003/default?load_balancing_policy=random"; - private final String ROUND_ROBIN_JDBC_URL = "jdbc:databend://localhost:8000,localhost:8002,localhost:8003/default?load_balancing_policy=round_robin"; - private final String FAIL_OVER_JDBC_URL = "jdbc:databend://localhost:7222,localhost:7223,localhost:7224,localhost:8000/default?load_balancing_policy=round_robin&max_failover_retry=4"; + private final String DEFAULT_JDBC_URL = "jdbc:databend://localhost:8000,localhost:8002,localhost:8003/default"; + private final String RANDOM_JDBC_URL = "jdbc:databend://localhost:8000,localhost:8002,localhost:8003/default?load_balancing_policy=random"; + private final String ROUND_ROBIN_JDBC_URL = "jdbc:databend://localhost:8000,localhost:8002,localhost:8003/default?load_balancing_policy=round_robin"; + private final String FAIL_OVER_JDBC_URL = "jdbc:databend://localhost:7222,localhost:7223,localhost:7224,localhost:8000/default?load_balancing_policy=round_robin&max_failover_retry=4"; + private Connection createConnection(String url) throws SQLException { return DriverManager.getConnection(url, "databend", "databend"); @@ -33,15 +33,15 @@ public void testDefaultLoadBalancing() statement.execute("select value from system.configs where name = 'http_handler_port';"); ResultSet r = statement.getResultSet(); r.next(); - if (r.getInt(1) == 8000) { - node8000++; - } else if (r.getInt(1) == 8002) { - node8002++; - } else if (r.getInt(1) == 8003) { - node8003++; - } else { - unknown++; - } + if (r.getInt(1) == 8000) { + node8000++; + } else if (r.getInt(1) == 8002) { + node8002++; + } else if (r.getInt(1) == 8003) { + node8003++; + } else { + unknown++; + } } } Assert.assertEquals(node8000, 100); diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/TestPrepareStatement.java b/databend-jdbc/src/test/java/com/databend/jdbc/TestPrepareStatement.java index b62c94ec..4e25b0fa 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/TestPrepareStatement.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/TestPrepareStatement.java @@ -6,16 +6,15 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import java.io.ByteArrayInputStream; -import java.io.InputStream; import java.sql.Connection; import java.sql.Date; import java.sql.DriverManager; -import java.sql.*; +import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.sql.Timestamp; +import java.sql.Types; import java.util.ArrayList; import java.util.List; diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/TestPresignContext.java b/databend-jdbc/src/test/java/com/databend/jdbc/TestPresignContext.java index 4366dd90..f1f653c3 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/TestPresignContext.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/TestPresignContext.java @@ -7,14 +7,13 @@ import java.sql.DriverManager; import java.sql.SQLException; -public class TestPresignContext -{ +public class TestPresignContext { private Connection createConnection() - throws SQLException - { + throws SQLException { String url = "jdbc:databend://localhost:8000"; return DriverManager.getConnection(url, "databend", "databend"); } + @Test(groups = {"Unit"}) public void TestPreisgnUrlBuild() { String presignSql = PresignContext.buildRequestSQL(PresignContext.PresignMethod.UPLOAD, "test_bucket", "test.csv"); @@ -33,8 +32,7 @@ public void TestGetPresignUrl() { Assert.assertNotNull(ctx); Assert.assertNotNull(ctx.getUrl()); Assert.assertNotNull(ctx.getHeaders()); - } - catch (Exception e) { + } catch (Exception e) { throw new RuntimeException(e); } } @@ -49,8 +47,7 @@ public void TestGetPresignUrlCase2() { Assert.assertNotNull(ctx); Assert.assertNotNull(ctx.getUrl()); Assert.assertNotNull(ctx.getHeaders()); - } - catch (Exception e) { + } catch (Exception e) { throw new RuntimeException(e); } } diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/TestStageAttachment.java b/databend-jdbc/src/test/java/com/databend/jdbc/TestStageAttachment.java index f18c4b1a..43a9f2bb 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/TestStageAttachment.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/TestStageAttachment.java @@ -3,21 +3,18 @@ import com.databend.client.StageAttachment; import org.testng.annotations.Test; -import java.time.LocalDateTime; -import java.util.UUID; - import static org.testng.Assert.assertEquals; public class TestStageAttachment { @Test(groups = {"Unit"}) - public void TestStageAttachment(){ + public void TestStageAttachment() { String uuid = "uuid/"; - String stagePrefix = "prefix/"+uuid; + String stagePrefix = "prefix/" + uuid; String fileName = "test"; String stagePath = "@~/" + stagePrefix + fileName; StageAttachment attachment = new StageAttachment.Builder().setLocation(stagePath) .build(); - assertEquals("StageAttachment{location=@~/prefix/uuid/test, file_format_options={type=CSV}, copy_options=null}",attachment.toString()); + assertEquals("StageAttachment{location=@~/prefix/uuid/test, file_format_options={type=CSV}, copy_options=null}", attachment.toString()); } } diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/TestTransaction.java b/databend-jdbc/src/test/java/com/databend/jdbc/TestTransaction.java index c26bcaf0..ce956b66 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/TestTransaction.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/TestTransaction.java @@ -4,7 +4,11 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; -import java.sql.*; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; public class TestTransaction { diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/cloud/TestDatabendCopyParams.java b/databend-jdbc/src/test/java/com/databend/jdbc/cloud/TestDatabendCopyParams.java index 08c45400..2fbc6106 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/cloud/TestDatabendCopyParams.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/cloud/TestDatabendCopyParams.java @@ -42,8 +42,8 @@ public void testDatabendStage() { DatabendStage s = DatabendStage.builder().stageName("~").path("jdbc/c2/").build(); prms = DatabendCopyParams.builder().setFiles(files).setDatabendStage(s).setPattern("a.txt").setType("parquet") .setCopyOptions(copyOptions).setFileOptions(fileOptions).build(); - assertEquals(prms.getDatabendStage().getStageName(),"~"); - assertEquals(prms.getDatabendStage().getPath(),"jdbc/c2/"); + assertEquals(prms.getDatabendStage().getStageName(), "~"); + assertEquals(prms.getDatabendStage().getPath(), "jdbc/c2/"); assertEquals(prms.getPattern(), "a.txt"); assertEquals(prms.getType(), "parquet"); assertEquals(prms.getFiles().size(), 2); diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/cloud/TestDatabendStage.java b/databend-jdbc/src/test/java/com/databend/jdbc/cloud/TestDatabendStage.java index b9b642f0..d83e75d2 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/cloud/TestDatabendStage.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/cloud/TestDatabendStage.java @@ -4,11 +4,9 @@ import static org.testng.Assert.assertEquals; -public class TestDatabendStage -{ +public class TestDatabendStage { @Test(groups = {"Unit"}) - public void testDatabendStage() - { + public void testDatabendStage() { DatabendStage stage = DatabendStage.builder() .stageName("stage_name") .path("path") @@ -19,8 +17,7 @@ public void testDatabendStage() } @Test(groups = {"Unit"}) - public void testDatabendStageWithExternalLocation() - { + public void testDatabendStageWithExternalLocation() { DatabendStage stage = DatabendStage.builder() .externalLocationS3(ExternalLocationS3.builder() .setLocation("s3://mybucket/path/a/b/c")