Skip to content
Merged
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 @@ -397,8 +397,6 @@ public String getTableExpression() {
// initialization inside inner classes.
public static final String PG_DESCRIPTION_CTE =
String.format(PgDescription.PG_DESCRIPTION_CTE_FORMAT, "0::bigint", "0::bigint");
public static final String PG_DESCRIPTION_CTE_EMULATED =
String.format(PgDescription.PG_DESCRIPTION_CTE_FORMAT, "''::varchar", "''::varchar");

public class PgDescription implements PgCatalogTable {
static final String PG_DESCRIPTION_CTE_FORMAT =
Expand All @@ -416,18 +414,10 @@ public ImmutableSet<TableOrIndexName> getDependencies() {

@Override
public String getTableExpression() {
return sessionState.isEmulatePgClassTables()
? PG_DESCRIPTION_CTE_EMULATED
: PG_DESCRIPTION_CTE;
return PG_DESCRIPTION_CTE;
}
}

// This is defined outside the PgType class, because Java 8 does not allow static initialization
// inside inner classes.
@InternalApi
public static final String PG_TYPE_CTE_EMULATED =
PgType.PG_TYPE_CTE.replace("0 as typrelid", "'0'::varchar as typrelid");

@InternalApi
public class PgType implements PgCatalogTable {
private final ImmutableSet<TableOrIndexName> DEPENDENCIES =
Expand Down Expand Up @@ -512,7 +502,7 @@ public class PgType implements PgCatalogTable {

@Override
public String getTableExpression() {
return sessionState.isEmulatePgClassTables() ? PG_TYPE_CTE_EMULATED : PG_TYPE_CTE;
return PG_TYPE_CTE;
}

@Override
Expand Down Expand Up @@ -615,8 +605,8 @@ public String getTableExpression() {
if (sessionState.isEmulatePgClassTables()) {
return String.format(
PG_CLASS_CTE,
"'''\"' || t.table_schema || '\".\"' || t.table_name || '\"'''",
"'''\"' || i.table_schema || '\".\"' || i.table_name || '\".\"' || i.index_name || '\"'''");
"mod(abs(spanner.farm_fingerprint(t.table_schema || '.' || t.table_name)), 2147483648)",
"mod(abs(spanner.farm_fingerprint(i.table_schema || '.' || i.table_name || '.' || i.index_name)), 2147483648)");
}
return String.format(PG_CLASS_CTE, "-1", "-1");
}
Expand Down Expand Up @@ -672,7 +662,7 @@ public class PgAttribute implements PgCatalogTable {

public static final String PG_ATTRIBUTE_CTE =
"pg_attribute as (\n"
+ "select '''\"' || table_schema || '\".\"' || table_name || '\"''' as attrelid,\n"
+ "select mod(abs(spanner.farm_fingerprint(table_schema || '.' || table_name)), 2147483648) as attrelid,\n"
+ " column_name as attname,\n"
+ " case regexp_replace(c.spanner_type, '\\(.*\\)', '')\n"
+ " when 'boolean' then 16\n"
Expand Down Expand Up @@ -712,7 +702,7 @@ public class PgAttribute implements PgCatalogTable {
+ " c.spanner_type\n"
+ "from information_schema.columns c\n"
+ "union all\n"
+ "select '''\"' || i.table_schema || '\".\"' || i.table_name || '\".\"' || i.index_name || '\"''' as attrelid,\n"
+ "select mod(abs(spanner.farm_fingerprint(i.table_schema || '.' || i.table_name || '.' || i.index_name)), 2147483648) as attrelid,\n"
+ " i.column_name as attname,\n"
+ " case regexp_replace(c.spanner_type, '\\(.*\\)', '')\n"
+ " when 'boolean' then 16\n"
Expand Down Expand Up @@ -770,8 +760,8 @@ public class PgAttrdef implements PgCatalogTable {

public static final String PG_ATTRDEF_CTE =
"pg_attrdef as (\n"
+ "select '''\"' || table_schema || '\".\"' || table_name || '\".\"' || column_name || '\"''' as oid,\n"
+ " '''\"' || table_schema || '\".\"' || table_name || '\"''' as adrelid,\n"
+ "select mod(abs(spanner.farm_fingerprint(table_schema || '.' || table_name || '.' || column_name)), 2147483648) as oid,\n"
+ " mod(abs(spanner.farm_fingerprint(table_schema || '.' || table_name)), 2147483648) as adrelid,\n"
+ " ordinal_position as adnum,\n"
+ " coalesce(column_default, generation_expression) as adbin\n"
+ "from information_schema.columns c\n"
Expand All @@ -788,17 +778,17 @@ public class PgConstraint implements PgCatalogTable {
public static final String PG_CONSTRAINT_CTE =
"pg_constraint as (\n"
+ "select\n"
+ " '''\"' || tc.constraint_schema || '\".\"' || tc.constraint_name || '\"''' as oid,\n"
+ " mod(abs(spanner.farm_fingerprint(tc.constraint_schema || '.' || tc.constraint_name)), 2147483648) as oid,\n"
+ " tc.constraint_name as conname, 2200 as connamespace,\n"
+ " case tc.constraint_type\n"
+ " when 'PRIMARY KEY' then 'p'\n"
+ " when 'CHECK' then 'c'\n"
+ " when 'FOREIGN KEY' then 'f'\n"
+ " else ''\n"
+ " end as contype, false as condeferrable, false as condeferred, true as convalidated,\n"
+ " '''\"' || tc.table_schema || '\".\"' || tc.table_name || '\"''' as conrelid,\n"
+ " mod(abs(spanner.farm_fingerprint(tc.table_schema || '.' || tc.table_name)), 2147483648) as conrelid,\n"
+ " 0::bigint as contypid, '0'::varchar as conindid, '0'::varchar as conparentid,\n"
+ " '''\"' || uc.table_schema || '\".\"' || uc.table_name || '\"''' as confrelid,\n"
+ " mod(abs(spanner.farm_fingerprint(uc.table_schema || '.' || uc.table_name)), 2147483648) as confrelid,\n"
+ " case rc.update_rule\n"
+ " when 'CASCADE' then 'c'\n"
+ " when 'NO ACTION' then 'a'\n"
Expand Down Expand Up @@ -887,8 +877,8 @@ public String getTableExpression() {
public class PgIndex implements PgCatalogTable {
public static final String PG_INDEX_CTE =
"pg_index as (\n"
+ "select '''\"' || i.table_schema || '\".\"' || i.table_name || '\".\"' || i.index_name || '\"''' as indexrelid,\n"
+ " '''\"' || i.table_schema || '\".\"' || i.table_name || '\"''' as indrelid,\n"
+ "select mod(abs(spanner.farm_fingerprint(i.table_schema || '.' || i.table_name || '.' || i.index_name)), 2147483648) as indexrelid,\n"
+ " mod(abs(spanner.farm_fingerprint(i.table_schema || '.' || i.table_name)), 2147483648) as indrelid,\n"
+ " count(1) as indnatts, sum(case ic.ordinal_position is null when true then 0 else 1 end) as indnkeyatts,\n"
+ " i.is_unique='YES' as indisunique, i.is_unique='YES' and i.is_null_filtered='NO' as indnullsnotdistinct,\n"
+ " i.index_type='PRIMARY_KEY' as indisprimary, false as indisexclusion, true as indimmediate,\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ public ImmutableList<String> getErrorHints(PGException exception) {
RegexQueryPartReplacer.replace(
Pattern.compile("pg_get_constraintdef\\s*\\(.+\\)\\s*AS\\s+"), "conbin AS "),
RegexQueryPartReplacer.replace(
Pattern.compile("'\"(.+?)\"'::regclass"), "'''\"public\".\"$1\"'''"),
Pattern.compile("'\"(.+?)\"'::regclass"),
"mod(abs(spanner.farm_fingerprint('public.$1')), 2147483648)"),
RegexQueryPartReplacer.replace(
Pattern.compile(
"string_agg\\(enum\\.enumlabel, ',' ORDER BY enum\\.enumsortorder\\)"),
"''::varchar"),
RegexQueryPartReplacer.replace(
Pattern.compile("(\\s+.+?)\\.oid::regclass::text"),
" substr($1.oid, 12, length($1.oid) - 13)"),
Pattern.compile("(\\s+.+?)\\.oid::regclass::text"), " $1.relname"),
RegexQueryPartReplacer.replace(
Pattern.compile(
"t\\.typinput\\s*=\\s*'array_in\\(\\s*cstring\\s*,\\s*oid,\\s*integer\\)'::regprocedure"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

package com.google.cloud.spanner.pgadapter;

import static com.google.cloud.spanner.pgadapter.statements.PgCatalog.PG_TYPE_CTE_EMULATED;
import static com.google.cloud.spanner.pgadapter.statements.PgCatalog.PgNamespace.PG_NAMESPACE_CTE;
import static com.google.cloud.spanner.pgadapter.statements.PgCatalog.PgType.PG_TYPE_CTE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -113,13 +113,13 @@
public abstract class AbstractMockServerTest {
private static final Logger logger = Logger.getLogger(AbstractMockServerTest.class.getName());

public static final String PG_TYPE_PREFIX = PG_NAMESPACE_CTE + ",\n" + PG_TYPE_CTE_EMULATED;
public static final String PG_TYPE_PREFIX = PG_NAMESPACE_CTE + ",\n" + PG_TYPE_CTE;
public static final String PG_CLASS_PREFIX = String.format(PgClass.PG_CLASS_CTE, "-1", "-1");
public static final String EMULATED_PG_CLASS_PREFIX =
String.format(
PgClass.PG_CLASS_CTE,
"'''\"' || t.table_schema || '\".\"' || t.table_name || '\"'''",
"'''\"' || i.table_schema || '\".\"' || i.table_name || '\".\"' || i.index_name || '\"'''");
"mod(abs(spanner.farm_fingerprint(t.table_schema || '.' || t.table_name)), 2147483648)",
"mod(abs(spanner.farm_fingerprint(i.table_schema || '.' || i.table_name || '.' || i.index_name)), 2147483648)");
public static final String EMULATED_PG_ATTRIBUTE_PREFIX = PgAttribute.PG_ATTRIBUTE_CTE;
public static final String EMULATED_PG_ATTRDEF_PREFIX = PgAttrdef.PG_ATTRDEF_CTE;

Expand Down
Loading
Loading