spanner/jdbc/src/main/java/com/example/spanner/jdbc/PartitionQueryExample.java [44:77]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  static void partitionQuery(String projectId, String instanceId, String databaseId)
      throws SQLException {
    String connectionUrl = String.format("jdbc:cloudspanner:/projects/%s/instances/%s/databases/%s",
        projectId, instanceId, databaseId);
    try (Connection connection = DriverManager.getConnection(
        connectionUrl); Statement statement = connection.createStatement()) {

      // Partition a query and then execute each partition sequentially.
      List<String> partitions = new ArrayList<>();
      // This will partition the query and return a result set with the partition IDs encoded as a
      // string. Each of these partition IDs can be executed with "RUN PARTITION '<partition-id>'".
      System.out.println("Partitioning query 'SELECT SingerId, FirstName, LastName from singers'");
      try (ResultSet partitionsResultSet = statement.executeQuery(
          "PARTITION SELECT SingerId, FirstName, LastName from Singers")) {
        while (partitionsResultSet.next()) {
          partitions.add(partitionsResultSet.getString(1));
        }
      }
      System.out.printf("Partition command returned %d partitions\n", partitions.size());

      // This executes the partitions serially on the same connection, but each partition can also
      // be executed on a different JDBC connection (even on a different host).
      for (String partitionId : partitions) {
        try (ResultSet resultSet = statement.executeQuery(
            String.format("RUN PARTITION '%s'", partitionId))) {
          while (resultSet.next()) {
            System.out.printf("%s %s %s%n", resultSet.getString(1), resultSet.getString(2),
                resultSet.getString(3));
          }
        }
      }
      System.out.println("Finished executing all partitions");
    }
  }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



spanner/jdbc/src/main/java/com/example/spanner/jdbc/PgPartitionQueryExample.java [43:76]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  static void partitionQuery(String projectId, String instanceId, String databaseId)
      throws SQLException {
    String connectionUrl = String.format("jdbc:cloudspanner:/projects/%s/instances/%s/databases/%s",
        projectId, instanceId, databaseId);
    try (Connection connection = DriverManager.getConnection(
        connectionUrl); Statement statement = connection.createStatement()) {

      // Partition a query and then execute each partition sequentially.
      List<String> partitions = new ArrayList<>();
      // This will partition the query and return a result set with the partition IDs encoded as a
      // string. Each of these partition IDs can be executed with "RUN PARTITION '<partition-id>'".
      System.out.println("Partitioning query 'SELECT SingerId, FirstName, LastName from singers'");
      try (ResultSet partitionsResultSet = statement.executeQuery(
          "PARTITION SELECT SingerId, FirstName, LastName from Singers")) {
        while (partitionsResultSet.next()) {
          partitions.add(partitionsResultSet.getString(1));
        }
      }
      System.out.printf("Partition command returned %d partitions\n", partitions.size());

      // This executes the partitions serially on the same connection, but each partition can also
      // be executed on a different JDBC connection (even on a different host).
      for (String partitionId : partitions) {
        try (ResultSet resultSet = statement.executeQuery(
            String.format("RUN PARTITION '%s'", partitionId))) {
          while (resultSet.next()) {
            System.out.printf("%s %s %s%n", resultSet.getString(1), resultSet.getString(2),
                resultSet.getString(3));
          }
        }
      }
      System.out.println("Finished executing all partitions");
    }
  }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



