diff --git a/src/main/java/ru/yandex/metrika/clickhouse/CHConnection.java b/src/main/java/ru/yandex/metrika/clickhouse/CHConnection.java index ef738d1a9095d138c61506385ebdf44c94003a1d..88948f740dce2f676fe1291cefef2bece4424cca 100644 --- a/src/main/java/ru/yandex/metrika/clickhouse/CHConnection.java +++ b/src/main/java/ru/yandex/metrika/clickhouse/CHConnection.java @@ -28,7 +28,7 @@ public class CHConnection implements Connection { String host = hostPort.substring(0, hostPort.indexOf(':')); String port = hostPort.substring(hostPort.indexOf(':') + 1); - ClickHouseSource source = new ClickHouseSource(host, port); + ClickHouseSource source = new ClickHouseSource(host, "default"); return new CHStatement(httpclient, source); } diff --git a/src/main/java/ru/yandex/metrika/clickhouse/CHDatabaseMetadata.java b/src/main/java/ru/yandex/metrika/clickhouse/CHDatabaseMetadata.java index a33ab50fede0627596aa33df952f21320857b4be..4ed72c8d8edfaed08efce6d97ced765abac04469 100644 --- a/src/main/java/ru/yandex/metrika/clickhouse/CHDatabaseMetadata.java +++ b/src/main/java/ru/yandex/metrika/clickhouse/CHDatabaseMetadata.java @@ -2,6 +2,7 @@ package ru.yandex.metrika.clickhouse; import ru.yandex.metrika.clickhouse.copypaste.CHResultBuilder; import ru.yandex.metrika.clickhouse.copypaste.CHResultSet; +import ru.yandex.metrika.clickhouse.util.Logger; import java.sql.*; import java.util.ArrayList; @@ -12,6 +13,8 @@ import java.util.List; */ public class CHDatabaseMetadata implements DatabaseMetaData { + private static final Logger log = Logger.of(CHDatabaseMetadata.class); + private String url; private CHConnection connection; @@ -797,6 +800,8 @@ public class CHDatabaseMetadata implements DatabaseMetaData { if (type.contains("Int")) { String bits = type.substring(type.indexOf("Int") + "Int".length()); row.add(bits); //bullshit + } else { + row.add(null); } // radix @@ -871,7 +876,124 @@ public class CHDatabaseMetadata implements DatabaseMetaData { @Override public ResultSet getTypeInfo() throws SQLException { - return null; + CHResultBuilder builder = CHResultBuilder.builder(18); + builder.names( + "TYPE_NAME", + "DATA_TYPE", + "PRECISION", + "LITERAL_PREFIX", + "LITERAL_SUFFIX", + "CREATE_PARAMS", + "NULLABLE", + "CASE_SENSITIVE", + "SEARCHABLE", + "UNSIGNED_ATTRIBUTE", + "FIXED_PREC_SCALE", + "AUTO_INCREMENT", + "LOCAL_TYPE_NAME", + "MINIMUM_SCALE", + "MAXIMUM_SCALE", + "SQL_DATA_TYPE", + "SQL_DATETIME_SUB", + "NUM_PREC_RADIX" + ); + builder.types( + "String", + "Int32", + "Int32", + "String", + "String", + "String", + "Int32", + "Int8", + "Int32", + "Int8", + "Int8", + "Int8", + "String", + "Int32", + "Int32", + "Int32", + "Int32", + "Int32" + ); + builder.addRow( + "String", Types.VARCHAR, + null, // precision - todo + '\'', '\'', null, + typeNoNulls, true, typeSearchable, + true, // unsigned + true, // fixed precision (money) + false, //auto-incr + null, + null, null, // scale - should be fixed + null, null, + 10 + ); + int[] sizes = { 8, 16, 32, 64 }; + boolean[] signed = { true, false }; + for (int size : sizes) { + for (boolean b: signed) { + String name = (b ? "" : "U") + "Int" + size; + builder.addRow( + name, (size <= 16 ? Types.INTEGER : Types.BIGINT), + null, // precision - todo + null, null, null, + typeNoNulls, true, typePredBasic, + !b, // unsigned + true, // fixed precision (money) + false, //auto-incr + null, + null, null, // scale - should be fixed + null, null, + 10 + ); + } + } + int[] floatSizes = { 32, 64 }; + for (int floatSize : floatSizes) { + String name = "Float" + floatSize; + builder.addRow( + name, Types.FLOAT, + null, // precision - todo + null, null, null, + typeNoNulls, true, typePredBasic, + false, // unsigned + true, // fixed precision (money) + false, //auto-incr + null, + null, null, // scale - should be fixed + null, null, + 10 + ); + } + builder.addRow( + "Date", Types.DATE, + null, // precision - todo + null, null, null, + typeNoNulls, true, typePredBasic, + false, // unsigned + true, // fixed precision (money) + false, //auto-incr + null, + null, null, // scale - should be fixed + null, null, + 10 + ); + builder.addRow( + "DateTime", Types.TIMESTAMP, + null, // precision - todo + null, null, null, + typeNoNulls, true, typePredBasic, + false, // unsigned + true, // fixed precision (money) + false, //auto-incr + null, + null, null, // scale - should be fixed + null, null, + 10 + ); + return builder.build(); } @Override diff --git a/src/main/java/ru/yandex/metrika/clickhouse/CHStatement.java b/src/main/java/ru/yandex/metrika/clickhouse/CHStatement.java index 43397fa22c62d38262b92c390db24b4c9623b755..482507302d0b86eefaf2bb935ed15f40d1eb9a6b 100644 --- a/src/main/java/ru/yandex/metrika/clickhouse/CHStatement.java +++ b/src/main/java/ru/yandex/metrika/clickhouse/CHStatement.java @@ -43,7 +43,6 @@ public class CHStatement implements Statement { @Override public ResultSet executeQuery(String sql) throws SQLException { - log.debug("Ex: " + sql); InputStream is = getInputStream(sql, null, false); try { return new CHResultSet(properties.isCompress() diff --git a/src/main/java/ru/yandex/metrika/clickhouse/copypaste/CHResultBuilder.java b/src/main/java/ru/yandex/metrika/clickhouse/copypaste/CHResultBuilder.java index b3588b9fadb890e218389f4f4117c2626874dbad..36290161f8ed0cc7a6f126c295baa2dec7120e26 100644 --- a/src/main/java/ru/yandex/metrika/clickhouse/copypaste/CHResultBuilder.java +++ b/src/main/java/ru/yandex/metrika/clickhouse/copypaste/CHResultBuilder.java @@ -16,7 +16,7 @@ public class CHResultBuilder { private final int columnsNum; private List<String> names; private List<String> types; - private List<List<Object>> rows = new ArrayList<List<Object>>(); + private List<List<?>> rows = new ArrayList<List<?>>(); public static CHResultBuilder builder(int columnsNum) { return new CHResultBuilder(columnsNum); @@ -39,19 +39,19 @@ public class CHResultBuilder { } public CHResultBuilder names(List<String> names) { - if (names.size() != columnsNum) throw new IllegalArgumentException("size mismatch"); + if (names.size() != columnsNum) throw new IllegalArgumentException("size mismatch, req: " + columnsNum + " got: " + names.size()); this.names = names; return this; } public CHResultBuilder types(List<String> types) { - if (types.size() != columnsNum) throw new IllegalArgumentException("size mismatch"); + if (types.size() != columnsNum) throw new IllegalArgumentException("size mismatch, req: " + columnsNum + " got: " + types.size()); this.types = types; return this; } - public CHResultBuilder addRow(List<Object> row) { - if (row.size() != columnsNum) throw new IllegalArgumentException("size mismatch"); + public CHResultBuilder addRow(List<?> row) { + if (row.size() != columnsNum) throw new IllegalArgumentException("size mismatch, req: " + columnsNum + " got: " + row.size()); rows.add(row); return this; } @@ -63,7 +63,7 @@ public class CHResultBuilder { ByteArrayOutputStream baos = new ByteArrayOutputStream(); appendRow(names, baos); appendRow(types, baos); - for (List<Object> row : rows) { + for (List<?> row : rows) { appendRow(row, baos); }