Skip to content

Commit 7663271

Browse files
committed
Reviewed max values
1 parent f9f588d commit 7663271

File tree

2 files changed

+66
-22
lines changed

2 files changed

+66
-22
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/metadata/DatabaseMetaDataImpl.java

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,27 @@
3131

3232
public class DatabaseMetaDataImpl implements java.sql.DatabaseMetaData, JdbcV2Wrapper {
3333
private static final Logger log = LoggerFactory.getLogger(DatabaseMetaDataImpl.class);
34+
35+
public enum TableType {
36+
DICTIONARY("DICTIONARY"),
37+
LOG_TABLE("LOG TABLE"),
38+
MEMORY_TABLE("MEMORY TABLE"),
39+
REMOTE_TABLE("REMOTE TABLE"),
40+
TABLE("TABLE"),
41+
VIEW("VIEW"),
42+
SYSTEM_TABLE("SYSTEM TABLE"),
43+
TEMPORARY_TABLE("TEMPORARY TABLE");
44+
45+
private final String typeName;
46+
47+
TableType(String typeName) {
48+
this.typeName = typeName;
49+
}
50+
51+
public String getTypeName() {
52+
return typeName;
53+
}
54+
}
3455
public static final String[] TABLE_TYPES = new String[] { "DICTIONARY", "LOG TABLE", "MEMORY TABLE",
3556
"REMOTE TABLE", "TABLE", "VIEW", "SYSTEM TABLE", "TEMPORARY TABLE" };
3657

@@ -544,107 +565,107 @@ public boolean supportsOpenStatementsAcrossRollback() throws SQLException {
544565

545566
@Override
546567
public int getMaxBinaryLiteralLength() throws SQLException {
547-
return 0;
568+
return Integer.MAX_VALUE;
548569
}
549570

550571
@Override
551572
public int getMaxCharLiteralLength() throws SQLException {
552-
return 0;
573+
return Integer.MAX_VALUE;
553574
}
554575

555576
@Override
556577
public int getMaxColumnNameLength() throws SQLException {
557-
return 0;
578+
return Short.MAX_VALUE;
558579
}
559580

560581
@Override
561582
public int getMaxColumnsInGroupBy() throws SQLException {
562-
return 0;
583+
return 0; // no limit
563584
}
564585

565586
@Override
566587
public int getMaxColumnsInIndex() throws SQLException {
567-
return 0;
588+
return 0; // no limit
568589
}
569590

570591
@Override
571592
public int getMaxColumnsInOrderBy() throws SQLException {
572-
return 0;
593+
return 0; // no limit
573594
}
574595

575596
@Override
576597
public int getMaxColumnsInSelect() throws SQLException {
577-
return 0;
598+
return 0; // no limit
578599
}
579600

580601
@Override
581602
public int getMaxColumnsInTable() throws SQLException {
582-
return 0;
603+
return 1000;
583604
}
584605

585606
@Override
586607
public int getMaxConnections() throws SQLException {
587-
return 0;
608+
return 150; // no limit in theory but 150 is too many from one client
588609
}
589610

590611
@Override
591612
public int getMaxCursorNameLength() throws SQLException {
592-
return 0;
613+
return 0; // no cursor - no limit
593614
}
594615

595616
@Override
596617
public int getMaxIndexLength() throws SQLException {
597-
return 0;
618+
return 0; // no limit
598619
}
599620

600621
@Override
601622
public int getMaxSchemaNameLength() throws SQLException {
602-
return 0;
623+
return Integer.MAX_VALUE;
603624
}
604625

605626
@Override
606627
public int getMaxProcedureNameLength() throws SQLException {
607-
return 0;
628+
return 0; // no limit
608629
}
609630

610631
@Override
611632
public int getMaxCatalogNameLength() throws SQLException {
612-
return 0;
633+
return 0; // no catalog - no limit
613634
}
614635

615636
@Override
616637
public int getMaxRowSize() throws SQLException {
617-
return 0;
638+
return 0; // no limit
618639
}
619640

620641
@Override
621642
public boolean doesMaxRowSizeIncludeBlobs() throws SQLException {
622-
return true;
643+
return true; // blobs sent as String as part of row data and not accessible from somehow else
623644
}
624645

625646
@Override
626647
public int getMaxStatementLength() throws SQLException {
627-
return 0;
648+
return 0; // there is configurable limit in ClickHouse but at this point we treat it as unknown.
628649
}
629650

630651
@Override
631652
public int getMaxStatements() throws SQLException {
632-
return 0;
653+
return getMaxConnections(); // as much as connections
633654
}
634655

635656
@Override
636657
public int getMaxTableNameLength() throws SQLException {
637-
return 0;
658+
return Integer.MAX_VALUE;
638659
}
639660

640661
@Override
641662
public int getMaxTablesInSelect() throws SQLException {
642-
return 0;
663+
return 0; // no limit
643664
}
644665

645666
@Override
646667
public int getMaxUserNameLength() throws SQLException {
647-
return 0;
668+
return 0; // unknown
648669
}
649670

650671
@Override
@@ -1541,7 +1562,7 @@ public boolean generatedKeyAlwaysReturned() throws SQLException {
15411562

15421563
@Override
15431564
public long getMaxLogicalLobSize() throws SQLException {
1544-
return 0;
1565+
return 0; // no limits - mainly stored as strings
15451566
}
15461567

15471568
@Override

jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/DatabaseMetaDataTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,29 @@ public void testGetTableTypes() throws Exception {
333333
}
334334
}
335335

336+
@Test
337+
public void testGetTablesReturnKnownTableTypes() throws Exception {
338+
try (Connection conn = getJdbcConnection()) {
339+
DatabaseMetaData dbmd = conn.getMetaData();
340+
341+
try (ResultSet rs = dbmd.getTables(null, "system", null, null)) {
342+
while (rs.next()) {
343+
String tableType = rs.getString("TABLE_TYPE");
344+
Assert.assertEquals(tableType, DatabaseMetaDataImpl.TableType.SYSTEM_TABLE.getTypeName());
345+
}
346+
}
347+
try (Statement stmt = conn.createStatement()){
348+
stmt.executeUpdate("CREATE TABLE test_db_metadata_type_memory (v Int32) ENGINE Memory");
349+
}
350+
try (ResultSet rs = dbmd.getTables(null, "default", "test_db_metadata_type_memory", null)) {
351+
while (rs.next()) {
352+
String tableType = rs.getString("TABLE_TYPE");
353+
Assert.assertEquals(tableType, DatabaseMetaDataImpl.TableType.MEMORY_TABLE.getTypeName());
354+
}
355+
}
356+
}
357+
}
358+
336359
@Test(groups = { "integration" }, enabled = false)
337360
public void testGetColumnsWithEmptyCatalog() throws Exception {
338361
// test not relevant until catalogs are implemented

0 commit comments

Comments
 (0)