Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -50,14 +50,16 @@ public abstract class JdbcMetadataProviderBase implements MetadataProvider {

protected final JdbcTablespace space;
protected final String databaseName;
protected final String mappedDatabaseName;

protected final String jdbcUri;

protected final Connection connection;

public JdbcMetadataProviderBase(JdbcTablespace space, String dbName) {
public JdbcMetadataProviderBase(JdbcTablespace space, String dbName, String mappedDatabaseName) {
this.space = space;
this.databaseName = dbName;
this.mappedDatabaseName = mappedDatabaseName;

ConnectionInfo connInfo = ConnectionInfo.fromURI(space.getUri());
this.jdbcUri = space.getUri().toASCIIString();
Expand Down Expand Up @@ -101,7 +103,7 @@ public Collection<String> getTables(@Nullable String schemaPattern, @Nullable St
ResultSet res = null;
List<String> tableNames = Lists.newArrayList();
try {
res = connection.getMetaData().getTables(databaseName, schemaPattern, tablePattern, GENERAL_TABLE_TYPES);
res = connection.getMetaData().getTables(mappedDatabaseName, schemaPattern, tablePattern, GENERAL_TABLE_TYPES);
while(res.next()) {
tableNames.add(res.getString("TABLE_NAME"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

public class PgSQLMetadataProvider extends JdbcMetadataProviderBase {

public PgSQLMetadataProvider(PgSQLTablespace space, String dbName) {
super(space, dbName);
public PgSQLMetadataProvider(PgSQLTablespace space, String dbName, String mappedDbName) {
super(space, dbName, mappedDbName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.tajo.storage.NullScanner;
import org.apache.tajo.storage.Scanner;
import org.apache.tajo.storage.fragment.Fragment;
import org.apache.tajo.storage.jdbc.ConnectionInfo;
import org.apache.tajo.storage.jdbc.JdbcFragment;
import org.apache.tajo.storage.jdbc.JdbcTablespace;

Expand All @@ -48,7 +49,7 @@ public PgSQLTablespace(String name, URI uri, JSONObject config) {
}

public MetadataProvider getMetadataProvider() {
return new PgSQLMetadataProvider(this, database);
return new PgSQLMetadataProvider(this, database, ConnectionInfo.fromURI(uri).database());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class PgSQLTestServer {
};

public static final String SPACENAME = "pgsql_cluster";
public static final String DATABASE_NAME = "tpch";
public static final String DATABASE_NAME = "pgsql_tpch";
public static final String USERNAME = "testuser";
public static final String PASSWORD = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.tajo.QueryTestCaseBase;
import org.apache.tajo.catalog.TableDesc;
import org.apache.tajo.client.TajoClient;
import org.apache.tajo.exception.UndefinedTableException;
import org.apache.tajo.exception.*;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -31,12 +31,12 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public class TestPgSQLEndPointTests extends QueryTestCaseBase {
private static final String jdbcUrl = PgSQLTestServer.getInstance().getJdbcUrlForAdmin();
private static TajoClient client;


@BeforeClass
public static void setUp() throws Exception {
QueryTestCaseBase.testingCluster.getMaster().refresh();
Expand All @@ -58,7 +58,7 @@ public void testGetAllDatabaseNames() {
public void testGetTableList() {
final Set<String> expected = Sets.newHashSet(PgSQLTestServer.TPCH_TABLES);
expected.add("datetime_types");
final Set<String> retrieved = Sets.newHashSet(client.getTableList("tpch"));
final Set<String> retrieved = Sets.newHashSet(client.getTableList("pgsql_tpch"));

assertEquals(expected, retrieved);
}
Expand All @@ -71,4 +71,13 @@ public void testGetTable() throws UndefinedTableException {
assertEquals(jdbcUrl + "&table=" + tableName, retrieved.getUri().toASCIIString());
}
}

@Test(expected = TajoRuntimeException.class)
public void testGetTableWithWrongDatabase() throws UndefinedTableException {
try {
client.getTableDesc("tpch" + "." + PgSQLTestServer.TPCH_TABLES[0]);
} catch (TajoException e) {
fail("database 'tpch' does not exist");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void testGetTablespaceName() throws Exception {
public void testGetDatabaseName() throws Exception {
Tablespace tablespace = TablespaceManager.get(jdbcUrl);
MetadataProvider provider = tablespace.getMetadataProvider();
assertEquals("tpch", provider.getDatabaseName());
assertEquals("pgsql_tpch", provider.getDatabaseName());
}

@Test
Expand Down Expand Up @@ -77,7 +77,7 @@ public void testGetTableDescriptor() throws Exception {

for (String tableName : PgSQLTestServer.TPCH_TABLES) {
TableDesc table = provider.getTableDesc(null, tableName);
assertEquals("tpch." + tableName, table.getName());
assertEquals("pgsql_tpch." + tableName, table.getName());
assertEquals(jdbcUrl + "&table=" + tableName, table.getUri().toASCIIString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SELECT
p_type,
p_size
FROM
default.region join tpch.nation on n_regionkey = r_regionkey and r_name = 'AMERICA'
default.region join pgsql_tpch.nation on n_regionkey = r_regionkey and r_name = 'AMERICA'
join default.supplier on s_nationkey = n_nationkey
join default.partsupp on s_suppkey = ps_suppkey
join default.part on p_partkey = ps_partkey and p_type like '%BRASS' and p_size = 15;