Java Code Examples for com.google.cloud.spanner.ReadOnlyTransaction#executeQuery()

The following examples show how to use com.google.cloud.spanner.ReadOnlyTransaction#executeQuery() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalReadSpannerSchema.java    From DataflowTemplates with Apache License 2.0 6 votes vote down vote up
private ResultSet readTableInfo(ReadOnlyTransaction tx) {
  // retrieve schema information for all tables, as well as aggregating the
  // number of indexes that cover each column. this will be used to estimate
  // the number of cells (table column plus indexes) mutated in an upsert operation
  // in order to stay below the 20k threshold
  return tx.executeQuery(
      Statement.of(
          "SELECT"
              + "    c.table_name"
              + "  , c.column_name"
              + "  , c.spanner_type"
              + "  , (1 + COALESCE(t.indices, 0)) AS cells_mutated"
              + "  FROM ("
              + "    SELECT c.table_name, c.column_name, c.spanner_type, c.ordinal_position"
              + "     FROM information_schema.columns as c"
              + "     WHERE c.table_catalog = '' AND c.table_schema = '') AS c"
              + "  LEFT OUTER JOIN ("
              + "    SELECT t.table_name, t.column_name, COUNT(*) AS indices"
              + "      FROM information_schema.index_columns AS t "
              + "      WHERE t.index_name != 'PRIMARY_KEY' AND t.table_catalog = ''"
              + "      AND t.table_schema = ''"
              + "      GROUP BY t.table_name, t.column_name) AS t"
              + "  USING (table_name, column_name)"
              + "  ORDER BY c.table_name, c.ordinal_position"));
}
 
Example 2
Source File: ReadSpannerSchema.java    From beam with Apache License 2.0 6 votes vote down vote up
private ResultSet readTableInfo(ReadOnlyTransaction tx) {
  // retrieve schema information for all tables, as well as aggregating the
  // number of indexes that cover each column. this will be used to estimate
  // the number of cells (table column plus indexes) mutated in an upsert operation
  // in order to stay below the 20k threshold
  return tx.executeQuery(
      Statement.of(
          "SELECT"
              + "    c.table_name"
              + "  , c.column_name"
              + "  , c.spanner_type"
              + "  , (1 + COALESCE(t.indices, 0)) AS cells_mutated"
              + "  FROM ("
              + "    SELECT c.table_name, c.column_name, c.spanner_type, c.ordinal_position"
              + "     FROM information_schema.columns as c"
              + "     WHERE c.table_catalog = '' AND c.table_schema = '') AS c"
              + "  LEFT OUTER JOIN ("
              + "    SELECT t.table_name, t.column_name, COUNT(*) AS indices"
              + "      FROM information_schema.index_columns AS t "
              + "      WHERE t.index_name != 'PRIMARY_KEY' AND t.table_catalog = ''"
              + "      AND t.table_schema = ''"
              + "      GROUP BY t.table_name, t.column_name) AS t"
              + "  USING (table_name, column_name)"
              + "  ORDER BY c.table_name, c.ordinal_position"));
}
 
Example 3
Source File: LocalReadSpannerSchema.java    From DataflowTemplates with Apache License 2.0 5 votes vote down vote up
private ResultSet readPrimaryKeyInfo(ReadOnlyTransaction tx) {
  return tx.executeQuery(
      Statement.of(
          "SELECT t.table_name, t.column_name, t.column_ordering"
              + " FROM information_schema.index_columns AS t "
              + " WHERE t.index_name = 'PRIMARY_KEY' AND t.table_catalog = ''"
              + " AND t.table_schema = ''"
              + " ORDER BY t.table_name, t.ordinal_position"));
}
 
Example 4
Source File: ReadSpannerSchema.java    From beam with Apache License 2.0 5 votes vote down vote up
private ResultSet readPrimaryKeyInfo(ReadOnlyTransaction tx) {
  return tx.executeQuery(
      Statement.of(
          "SELECT t.table_name, t.column_name, t.column_ordering"
              + " FROM information_schema.index_columns AS t "
              + " WHERE t.index_name = 'PRIMARY_KEY' AND t.table_catalog = ''"
              + " AND t.table_schema = ''"
              + " ORDER BY t.table_name, t.ordinal_position"));
}