Skip to content

Commit

Permalink
[BugFix] copy properties for pg otherwise properties is populated (St…
Browse files Browse the repository at this point in the history
…arRocks#29825)

* [BugFix] copy properties for pg otherwise properties is populated

Signed-off-by: zombee0 <[email protected]>
  • Loading branch information
zombee0 authored Aug 24, 2023
1 parent 6fa8f81 commit fbfb7ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -67,18 +68,20 @@ public List<Column> convertToSRTable(ResultSet columnSet) throws SQLException {
@Override
public Table getTable(long id, String name, List<Column> schema, String dbName, String catalogName,
Map<String, String> properties) throws DdlException {
properties.putIfAbsent(JDBCTable.ORIGINAL_DBNAME, dbName);
properties.putIfAbsent(JDBCTable.ORIGINAL_TABLENAME, name);
return new JDBCTable(id, "\"" + dbName + "\"" + "." + "\"" + name + "\"", schema, "", catalogName, properties);
Map<String, String> newProp = new HashMap<>(properties);
newProp.putIfAbsent(JDBCTable.ORIGINAL_DBNAME, dbName);
newProp.putIfAbsent(JDBCTable.ORIGINAL_TABLENAME, name);
return new JDBCTable(id, "\"" + dbName + "\"" + "." + "\"" + name + "\"", schema, "", catalogName, newProp);
}

@Override
public Table getTable(long id, String name, List<Column> schema, List<Column> partitionColumns, String dbName,
String catalogName, Map<String, String> properties) throws DdlException {
properties.putIfAbsent(JDBCTable.ORIGINAL_DBNAME, dbName);
properties.putIfAbsent(JDBCTable.ORIGINAL_TABLENAME, name);
Map<String, String> newProp = new HashMap<>(properties);
newProp.putIfAbsent(JDBCTable.ORIGINAL_DBNAME, dbName);
newProp.putIfAbsent(JDBCTable.ORIGINAL_TABLENAME, name);
return new JDBCTable(id, "\"" + dbName + "\"" + "." + "\"" + name + "\"", schema, partitionColumns,
"", catalogName, properties);
"", catalogName, newProp);
}

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

import com.google.common.collect.Lists;
import com.mockrunner.mock.jdbc.MockResultSet;
import com.starrocks.catalog.Column;
import com.starrocks.catalog.Database;
import com.starrocks.catalog.JDBCResource;
import com.starrocks.catalog.JDBCTable;
Expand All @@ -29,6 +30,7 @@

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Arrays;
Expand Down Expand Up @@ -168,6 +170,13 @@ public void testGetTable() throws SQLException {
Assert.assertTrue(table instanceof JDBCTable);
Assert.assertEquals("catalog.test.tbl1", table.getUUID());
Assert.assertEquals("\"test\".\"tbl1\"", table.getName());
Assert.assertNull(properties.get(JDBCTable.ORIGINAL_TABLENAME));
PostgresSchemaResolver postgresSchemaResolver = new PostgresSchemaResolver();
ResultSet columnSet = postgresSchemaResolver.getColumns(connection, "test", "tbl1");
List<Column> fullSchema = postgresSchemaResolver.convertToSRTable(columnSet);
Table table1 = postgresSchemaResolver.getTable(1, "tbl1", fullSchema, "test", "catalog", properties);
Assert.assertTrue(table1 instanceof JDBCTable);
Assert.assertNull(properties.get(JDBCTable.ORIGINAL_TABLENAME));
} catch (Exception e) {
System.out.println(e.getMessage());
Assert.fail();
Expand Down

0 comments on commit fbfb7ed

Please sign in to comment.