|
14 | 14 | import com.clickhouse.client.api.internal.ServerSettings; |
15 | 15 | import com.clickhouse.client.api.metadata.DefaultColumnToMethodMatchingStrategy; |
16 | 16 | import com.clickhouse.client.api.metadata.TableSchema; |
| 17 | +import com.clickhouse.client.api.query.QuerySettings; |
17 | 18 | import com.clickhouse.data.ClickHouseColumn; |
| 19 | +import com.clickhouse.data.ClickHouseDataType; |
18 | 20 | import com.clickhouse.data.ClickHouseRecord; |
19 | 21 | import org.testng.Assert; |
20 | 22 | import org.testng.annotations.BeforeMethod; |
@@ -49,6 +51,24 @@ public void testGetTableSchema() { |
49 | 51 | Assert.assertEquals(columns.get(0).getDataType().name(), "UInt32"); |
50 | 52 | } |
51 | 53 |
|
| 54 | + @Test(groups = { "integration" }) |
| 55 | + |
| 56 | + public void testGetTableSchemaDifferentDb() throws Exception { |
| 57 | + String table = "test_get_table_schema_different_db"; |
| 58 | + String db = ClickHouseServerForTest.getDatabase() + "_schema_test" ; |
| 59 | + try { |
| 60 | + QuerySettings settings = new QuerySettings().setDatabase(db); |
| 61 | + client.execute("DROP DATABASE IF EXISTS " + db).get().close(); |
| 62 | + client.execute("CREATE DATABASE " + db).get().close(); |
| 63 | + client.query("DROP TABLE IF EXISTS " + table, settings).get().close(); |
| 64 | + client.query("CREATE TABLE " + table + " (rowId Int32) Engine=MergeTree ORDER BY ()", settings).get().close(); |
| 65 | + TableSchema tableSchema = client.getTableSchema(table, db); |
| 66 | + Assert.assertEquals(tableSchema.getColumnByName("rowId").getDataType(), ClickHouseDataType.Int32); |
| 67 | + } finally { |
| 68 | + client.execute("DROP DATABASE IF EXISTS " + db).get().close(); |
| 69 | + } |
| 70 | + } |
| 71 | + |
52 | 72 | private void prepareDataSet(String tableName) { |
53 | 73 |
|
54 | 74 | try { |
|
0 commit comments