Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.Set;

// all possible JDBC properties options currently supported by databend driver
final class ConnectionProperties {
public final class ConnectionProperties {
public static final ConnectionProperty<String> USER = new User();
public static final ConnectionProperty<String> PASSWORD = new Password();
public static final ConnectionProperty<Boolean> SSL = new Ssl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import static java.util.Objects.requireNonNull;

class DatabendColumnInfo {
public class DatabendColumnInfo {
private static final int VARBINARY_MAX = 1024 * 1024 * 1024;
// current longest time zone is 32
private static final int TIME_ZONE_MAX = 40;
Expand Down Expand Up @@ -362,6 +362,4 @@ public DatabendColumnInfo build() {
catalogName);
}
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.databend.jdbc;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;

/**
Expand All @@ -13,7 +14,7 @@
* data streams in Databend.
* </p>
*/
public interface DatabendConnection {
public interface DatabendConnection extends Connection {

/**
* Enumeration of available loading strategies for streaming data into tables.
Expand Down Expand Up @@ -56,7 +57,6 @@ enum LoadMethod {
*
* @param stageName the stage which contains the file
* @param sourceFileName the file name in the stage
* @param decompress whether to decompress the data
* @return the input stream of the file
* @throws SQLException failed to download input stream
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class DatabendConnectionImpl implements Connection, DatabendConnection, FileTran
private Semver serverVersion = null;
private Capability serverCapability = null;

static volatile ExecutorService heartbeatScheduler = null;
private static volatile ExecutorService heartbeatScheduler = null;
private final HeartbeatManager heartbeatManager = new HeartbeatManager();

private void initializeFileHandler() {
Expand Down Expand Up @@ -1331,8 +1331,8 @@ boolean isHeartbeatStopped() {
}

static class RetryPolicy {
boolean ignore404;
boolean retry503;
private boolean ignore404;
private boolean retry503;
RetryPolicy(boolean ignore404, boolean retry503) {
this.ignore404 = ignore404;
this.retry503 = retry503;
Expand All @@ -1352,7 +1352,7 @@ boolean shouldRetry(IOException e) {
}

static class ResponseWithBody {
public Response response;
public Response response;
public String body;

ResponseWithBody(Response response, String body) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @author wayne
*/
public class DatabendConstant {
class DatabendConstant {
public static final String ENABLE_STR = "enable";
public static final String BASE64_STR = "base64";
public static final Pattern INSERT_INTO_PATTERN = Pattern.compile("(insert|replace)\\s+into");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static com.databend.jdbc.DriverInfo.*;
import static java.util.Objects.requireNonNull;

class DatabendDatabaseMetaData implements DatabaseMetaData {
public class DatabendDatabaseMetaData implements DatabaseMetaData {
private static final String SEARCH_STRING_ESCAPE = "\\";
private final DatabendConnectionImpl connection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import static java.time.format.DateTimeFormatter.ISO_LOCAL_TIME;
import static java.util.Objects.requireNonNull;

class DatabendPreparedStatement extends DatabendStatement implements PreparedStatement {
public class DatabendPreparedStatement extends DatabendStatement implements PreparedStatement {
private static final Logger logger = Logger.getLogger(DatabendPreparedStatement.class.getPackage().getName());
static final DateTimeFormatter DATE_FORMATTER = ISODateTimeFormat.date();
private final RawStatementWrapper rawStatement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.Executors.newCachedThreadPool;

class DatabendResultSet extends AbstractDatabendResultSet {
public class DatabendResultSet extends AbstractDatabendResultSet {
private final Statement statement;
private final DatabendClient client;
@GuardedBy("this")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.sql.Types;
import java.util.List;

class DatabendResultSetMetaData implements ResultSetMetaData {
public class DatabendResultSetMetaData implements ResultSetMetaData {
private final List<DatabendColumnInfo> databendColumnInfo;

DatabendResultSetMetaData(List<DatabendColumnInfo> databendColumnInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static java.lang.Math.toIntExact;
import static java.util.Objects.requireNonNull;

class DatabendStatement implements Statement {
public class DatabendStatement implements Statement {
private final AtomicReference<DatabendConnectionImpl> connection;
private final Consumer<DatabendStatement> onClose;
private int currentUpdateCount = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import java.sql.Types;

class JdbcTypeMapping {
public class JdbcTypeMapping {
/**
* Converts {@link DatabendColumnInfo} to generic SQL type defined in JDBC.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@UtilityClass
@CustomLog
class LoggerUtil {
public class LoggerUtil {

private static Boolean slf4jAvailable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;

public class Compatibility {
public static class Capability {
Expand Down Expand Up @@ -87,7 +86,7 @@ static Object invokeMethod(Object target, String methodName,
}
}

static Object invokeMethodNoArg(Object target, String methodName) {
public static Object invokeMethodNoArg(Object target, String methodName) {
return invokeMethod(target, methodName, new Class<?>[0], new Object[0]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.databend.jdbc.cloud;

import com.databend.client.data.DatabendDataType;
import com.databend.client.data.DatabendRawType;
import com.databend.jdbc.*;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.sql.*;


public class TestSpecifiedAPI {
static String port = System.getenv("DATABEND_TEST_CONN_PORT") != null ? System.getenv("DATABEND_TEST_CONN_PORT").trim() : "8000";
static String username = "databend";
static String password = "databend";

public static String baseURL() {
return "jdbc:databend://localhost:" + port;
}

public static Connection createConnection()
throws SQLException {
return DriverManager.getConnection(baseURL(), username, password);
}

@Test(groups = {"IT"})
public void testUnwrap()
throws SQLException {
try (Connection conn = createConnection()) {
DatabendConnection connection = conn.unwrap(DatabendConnection.class);


// DatabendStatement: no specified public method
DatabendStatement statement = connection.createStatement().unwrap(DatabendStatement.class);
statement.execute("create or replace table test_unwrap(c1 int32)");
//statement.execute("insert into test_unwrap values (1)");
statement.execute("create or replace stage test_unwrap");

// DatabendConnection: local file APIs
String testData = "1234";
DatabendConnection.LoadMethod m = DatabendConnection.LoadMethod.STAGE;
InputStream inputStream = new ByteArrayInputStream(testData.getBytes(StandardCharsets.UTF_8));
connection.uploadStream(inputStream, "test_unwrap", "dir1", "f1", 4, false);

// DatabendPreparedStatement: no specified public method
DatabendPreparedStatement ps = connection.prepareStatement("select 1").unwrap(DatabendPreparedStatement.class);

try(DatabendResultSet rs = statement.executeQuery("select * from test_unwrap").unwrap(DatabendResultSet.class)) {
Assert.assertEquals(rs.columnIndex("c1"), 1);
}

DatabendDatabaseMetaData dbMeta = connection.getMetaData().unwrap(DatabendDatabaseMetaData.class);
try (ResultSet rs = dbMeta.getColumns(null, "default", "test_unwrap", new String[]{"c1"})) {
Assert.assertTrue(rs.next());
Assert.assertEquals(rs.getString("COLUMN_NAME"), "c1");
Assert.assertFalse(rs.next());
}
}
}
@Test(groups = {"UNIT"})
public void testUtils() {
ConnectionProperties.allProperties();
ConnectionProperties.getDefaults();

DatabendRawType rawType = new DatabendRawType("Nullable(int32)");
DatabendDataType t = rawType.getDataType();
Assert.assertEquals(t, DatabendDataType.INT_32);
DatabendColumnInfo.Builder builder = DatabendColumnInfo.newBuilder("c1", rawType);
DatabendColumnInfo ci = builder.build();
Assert.assertEquals(ci.getColumnName(), "c1");
Assert.assertEquals(new JdbcTypeMapping().toSqlType(ci), Types.INTEGER);
}
}
Loading