Skip to content

Commit

Permalink
Revert "Added support for WHERE ... IS NOT NULL for indexes (GoogleCl…
Browse files Browse the repository at this point in the history
  • Loading branch information
darshan-sj authored Sep 25, 2024
1 parent 8f14b1b commit 1430d47
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public abstract class Index implements Serializable {
// restricted for gsql
abstract boolean nullFiltered();

// restricted for pg
@Nullable
abstract String filter();

Expand Down Expand Up @@ -178,11 +179,6 @@ private void prettyPrintGsql(Appendable appendable) throws IOException {
if (interleaveIn() != null) {
appendable.append(", INTERLEAVE IN ").append(quoteIdentifier(interleaveIn(), dialect()));
}

if (!nullFiltered() && filter() != null && !filter().isEmpty()) {
appendable.append(" WHERE ").append(filter());
}

if (options() != null) {
String optionsString = String.join(",", options());
if (!optionsString.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,23 +399,26 @@ private void listIndexes(Map<String, NavigableMap<String, Index.Builder>> indexe
(dialect == Dialect.GOOGLE_STANDARD_SQL)
? resultSet.getBoolean(5)
: resultSet.getString(5).equalsIgnoreCase("YES");
String filter = resultSet.isNull(6) ? null : resultSet.getString(6);
String filter =
(dialect == Dialect.GOOGLE_STANDARD_SQL || resultSet.isNull(6))
? null
: resultSet.getString(6);

// Note that 'type' is only queried from GoogleSQL and is not from Postgres and
// the number of columns will be different.
String type =
(dialect == Dialect.GOOGLE_STANDARD_SQL && !resultSet.isNull(7))
? resultSet.getString(7)
(dialect == Dialect.GOOGLE_STANDARD_SQL && !resultSet.isNull(6))
? resultSet.getString(6)
: null;

ImmutableList<String> searchPartitionBy =
(dialect == Dialect.GOOGLE_STANDARD_SQL && !resultSet.isNull(8))
? ImmutableList.<String>builder().addAll(resultSet.getStringList(8)).build()
(dialect == Dialect.GOOGLE_STANDARD_SQL && !resultSet.isNull(7))
? ImmutableList.<String>builder().addAll(resultSet.getStringList(7)).build()
: null;

ImmutableList<String> searchOrderBy =
(dialect == Dialect.GOOGLE_STANDARD_SQL && !resultSet.isNull(9))
? ImmutableList.<String>builder().addAll(resultSet.getStringList(9)).build()
(dialect == Dialect.GOOGLE_STANDARD_SQL && !resultSet.isNull(8))
? ImmutableList.<String>builder().addAll(resultSet.getStringList(8)).build()
: null;

Map<String, Index.Builder> tableIndexes =
Expand All @@ -442,7 +445,7 @@ Statement listIndexesSQL() {
case GOOGLE_STANDARD_SQL:
return Statement.of(
"SELECT t.table_schema, t.table_name, t.index_name, t.parent_table_name, t.is_unique,"
+ " t.is_null_filtered, t.filter, t.index_type, t.search_partition_by, t.search_order_by"
+ " t.is_null_filtered, t.index_type, t.search_partition_by, t.search_order_by"
+ " FROM information_schema.indexes AS t"
+ " WHERE t.table_schema NOT IN"
+ " ('INFORMATION_SCHEMA', 'SPANNER_SYS') AND"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ public void indexes() throws Exception {
+ " ) PRIMARY KEY (`id` ASC)",
" CREATE UNIQUE NULL_FILTERED INDEX `a_last_name_idx` ON "
+ " `Users`(`last_name` ASC) STORING (`first_name`)",
" CREATE INDEX `b_age_idx` ON `Users`(`age` DESC) WHERE age IS NOT NULL",
" CREATE INDEX `b_age_idx` ON `Users`(`age` DESC)",
" CREATE UNIQUE INDEX `c_first_name_idx` ON `Users`(`first_name` ASC)");

SPANNER_SERVER.createDatabase(dbId, statements);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void testListIndexesSQL() {
googleSQLInfoScanner.listIndexesSQL().getSql(),
equalToCompressingWhiteSpace(
"SELECT t.table_schema, t.table_name, t.index_name, t.parent_table_name, t.is_unique,"
+ " t.is_null_filtered, t.filter, t.index_type, t.search_partition_by, t.search_order_by"
+ " t.is_null_filtered, t.index_type, t.search_partition_by, t.search_order_by"
+ " FROM information_schema.indexes AS t"
+ " WHERE t.table_schema NOT IN"
+ " ('INFORMATION_SCHEMA', 'SPANNER_SYS') AND"
Expand Down

0 comments on commit 1430d47

Please sign in to comment.