Search in sources :

Example 1 with MatcherStatement

use of com.google.cloud.spanner.pgadapter.statements.MatcherStatement in project pgadapter by GoogleCloudPlatform.

the class PSQLTest method testDescribeTranslates.

@Test
public void testDescribeTranslates() {
    // PSQL equivalent: \d
    String sql = "SELECT n.nspname as \"Schema\",\n" + "  c.relname as \"Name\",\n" + "  CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN" + " 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN" + " 'special' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'partitioned table' WHEN 'I'" + " THEN 'partitioned index' END as \"Type\",\n" + "  pg_catalog.pg_get_userbyid(c.relowner) as \"Owner\"\n" + "FROM pg_catalog.pg_class c\n" + "     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" + "WHERE c.relkind IN ('r','p','v','m','S','f','')\n" + "      AND n.nspname <> 'pg_catalog'\n" + "      AND n.nspname <> 'information_schema'\n" + "      AND n.nspname !~ '^pg_toast'\n" + "  AND pg_catalog.pg_table_is_visible(c.oid)\n" + "ORDER BY 1,2;";
    String expected = "SELECT" + " t.table_schema as \"Schema\"," + " t.table_name as \"Name\"," + " 'table' as \"Type\"," + " 'me' as \"Owner\" " + "FROM" + " information_schema.tables AS t " + "WHERE" + " t.table_schema = 'public'";
    MatcherStatement matcherStatement = new MatcherStatement(options, parse(sql), connectionHandler);
    assertEquals(expected, matcherStatement.getSql());
}
Also used : MatcherStatement(com.google.cloud.spanner.pgadapter.statements.MatcherStatement) Test(org.junit.Test)

Example 2 with MatcherStatement

use of com.google.cloud.spanner.pgadapter.statements.MatcherStatement in project pgadapter by GoogleCloudPlatform.

the class PSQLTest method testDescribeMoreTableAttributesTranslates.

@Test
public void testDescribeMoreTableAttributesTranslates() {
    // PSQL equivalent: \d <table> (5)
    String sql = "SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i" + " WHERE c.oid=i.inhrelid AND i.inhparent = '-2264987671676060158' ORDER BY" + " c.relname;";
    String expected = "SELECT 1 LIMIT 0";
    MatcherStatement matcherStatement = new MatcherStatement(options, parse(sql), connectionHandler);
    assertEquals(expected, matcherStatement.getSql());
}
Also used : MatcherStatement(com.google.cloud.spanner.pgadapter.statements.MatcherStatement) Test(org.junit.Test)

Example 3 with MatcherStatement

use of com.google.cloud.spanner.pgadapter.statements.MatcherStatement in project pgadapter by GoogleCloudPlatform.

the class PSQLTest method testListDatabaseCommandTranslates.

@Test
public void testListDatabaseCommandTranslates() {
    // PSQL equivalent: \l <table>
    String sql = "SELECT d.datname as \"Name\",\n" + "       pg_catalog.pg_get_userbyid(d.datdba) as \"Owner\",\n" + "       pg_catalog.pg_encoding_to_char(d.encoding) as \"Encoding\",\n" + "       pg_catalog.array_to_string(d.datacl, '\\n') AS \"Access privileges\"\n" + "FROM pg_catalog.pg_database d\n" + "WHERE d.datname OPERATOR(pg_catalog.~) '^(users)$'\n" + "ORDER BY 1;";
    String expected = "SELECT '' AS Name";
    MatcherStatement matcherStatement = new MatcherStatement(options, parse(sql), connectionHandler);
    assertEquals(expected, matcherStatement.getSql());
}
Also used : MatcherStatement(com.google.cloud.spanner.pgadapter.statements.MatcherStatement) Test(org.junit.Test)

Example 4 with MatcherStatement

use of com.google.cloud.spanner.pgadapter.statements.MatcherStatement in project pgadapter by GoogleCloudPlatform.

the class PSQLTest method testDescribeTableMatchTranslates.

@Test
public void testDescribeTableMatchTranslates() {
    // PSQL equivalent: \d <table> (1)
    String sql = "SELECT c.oid,\n" + "  n.nspname,\n" + "  c.relname\n" + "FROM pg_catalog.pg_class c\n" + "     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" + "WHERE c.relname OPERATOR(pg_catalog.~) '^(users)$'\n" + "  AND pg_catalog.pg_table_is_visible(c.oid)\n" + "ORDER BY 2, 3;";
    String expected = "SELECT" + " t.table_name as oid," + " 'public' as nspname," + " t.table_name as relname" + " FROM" + " information_schema.tables AS t" + " WHERE" + " t.table_schema='public'" + " AND" + " LOWER(t.table_name) = LOWER('users')";
    MatcherStatement matcherStatement = new MatcherStatement(options, parse(sql), connectionHandler);
    assertEquals(expected, matcherStatement.getSql());
}
Also used : MatcherStatement(com.google.cloud.spanner.pgadapter.statements.MatcherStatement) Test(org.junit.Test)

Example 5 with MatcherStatement

use of com.google.cloud.spanner.pgadapter.statements.MatcherStatement in project pgadapter by GoogleCloudPlatform.

the class PSQLTest method testDescribeAllIndexMetadataTranslates.

@Test
public void testDescribeAllIndexMetadataTranslates() {
    // PSQL equivalent: \di
    String sql = "SELECT n.nspname as \"Schema\",\n" + "  c.relname as \"Name\",\n" + "  CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN" + " 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN" + " 'special' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'partitioned table' WHEN 'I'" + " THEN 'partitioned index' END as \"Type\",\n" + "  pg_catalog.pg_get_userbyid(c.relowner) as \"Owner\",\n" + " c2.relname as \"Table\"\n" + "FROM pg_catalog.pg_class c\n" + "     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" + "     LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid\n" + "     LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid\n" + "WHERE c.relkind IN ('i','I','')\n" + "      AND n.nspname <> 'pg_catalog'\n" + "      AND n.nspname <> 'information_schema'\n" + "      AND n.nspname !~ '^pg_toast'\n" + "  AND pg_catalog.pg_table_is_visible(c.oid)\n" + "ORDER BY 1,2;";
    String expected = "SELECT table_catalog, table_schema, table_name, index_name, index_type, parent_table_name, is_unique, is_null_filtered, index_state, spanner_is_managed FROM information_schema.indexes";
    MatcherStatement matcherStatement = new MatcherStatement(options, parse(sql), connectionHandler);
    assertEquals(expected, matcherStatement.getSql());
}
Also used : MatcherStatement(com.google.cloud.spanner.pgadapter.statements.MatcherStatement) Test(org.junit.Test)

Aggregations

MatcherStatement (com.google.cloud.spanner.pgadapter.statements.MatcherStatement)29 Test (org.junit.Test)29 JSONParser (org.json.simple.parser.JSONParser)2