public void bulkIngestAppend()

in java/driver/validation/src/main/java/org/apache/arrow/adbc/driver/testsuite/AbstractStatementTest.java [94:188]


  public void bulkIngestAppend() throws Exception {
    // Implementations vary on the integer type here.
    try (final VectorSchemaRoot root32 = VectorSchemaRoot.create(schema32, allocator);
        final VectorSchemaRoot root64 = VectorSchemaRoot.create(schema64, allocator)) {
      {
        final IntVector ints = (IntVector) root32.getVector(0);
        final VarCharVector strs = (VarCharVector) root32.getVector(1);

        ints.allocateNew(4);
        ints.setSafe(0, 0);
        ints.setSafe(1, 1);
        ints.setSafe(2, 2);
        ints.setNull(3);
        strs.allocateNew(4);
        strs.setNull(0);
        strs.setSafe(1, "foo".getBytes(StandardCharsets.UTF_8));
        strs.setSafe(2, "".getBytes(StandardCharsets.UTF_8));
        strs.setSafe(3, "asdf".getBytes(StandardCharsets.UTF_8));
        root32.setRowCount(4);
      }
      {
        final BigIntVector ints = (BigIntVector) root64.getVector(0);
        final VarCharVector strs = (VarCharVector) root64.getVector(1);

        ints.allocateNew(4);
        ints.setSafe(0, 0);
        ints.setSafe(1, 1);
        ints.setSafe(2, 2);
        ints.setNull(3);
        strs.allocateNew(4);
        strs.setNull(0);
        strs.setSafe(1, "foo".getBytes(StandardCharsets.UTF_8));
        strs.setSafe(2, "".getBytes(StandardCharsets.UTF_8));
        strs.setSafe(3, "asdf".getBytes(StandardCharsets.UTF_8));
        root64.setRowCount(4);
      }

      try (final AdbcStatement stmt = connection.bulkIngest(tableName, BulkIngestMode.CREATE)) {
        stmt.bind(root32);
        stmt.executeUpdate();
      }
      try (final AdbcStatement stmt = connection.createStatement()) {
        stmt.setSqlQuery("SELECT * FROM " + tableName);
        try (AdbcStatement.QueryResult queryResult = stmt.executeQuery()) {
          assertThat(queryResult.getReader().loadNextBatch()).isTrue();
          assertThat(queryResult.getReader().getVectorSchemaRoot())
              .satisfiesAnyOf(
                  data -> assertRoot(data).isEqualTo(root32),
                  data -> assertRoot(data).isEqualTo(root64));
        }
      }

      // Append
      try (final AdbcStatement stmt = connection.bulkIngest(tableName, BulkIngestMode.APPEND)) {
        stmt.bind(root32);
        stmt.executeUpdate();
      }
      try (final AdbcStatement stmt = connection.createStatement()) {
        stmt.setSqlQuery("SELECT * FROM " + tableName);
        try (AdbcStatement.QueryResult queryResult = stmt.executeQuery()) {
          assertThat(queryResult.getReader().loadNextBatch()).isTrue();
          {
            root32.setRowCount(8);
            final IntVector ints = (IntVector) root32.getVector(0);
            final VarCharVector strs = (VarCharVector) root32.getVector(1);
            ints.setSafe(4, 0);
            ints.setSafe(5, 1);
            ints.setSafe(6, 2);
            ints.setNull(7);
            strs.setNull(4);
            strs.setSafe(5, "foo".getBytes(StandardCharsets.UTF_8));
            strs.setSafe(6, "".getBytes(StandardCharsets.UTF_8));
            strs.setSafe(7, "asdf".getBytes(StandardCharsets.UTF_8));
          }
          {
            root64.setRowCount(8);
            final BigIntVector ints = (BigIntVector) root64.getVector(0);
            final VarCharVector strs = (VarCharVector) root64.getVector(1);
            ints.setSafe(4, 0);
            ints.setSafe(5, 1);
            ints.setSafe(6, 2);
            ints.setNull(7);
            strs.setNull(4);
            strs.setSafe(5, "foo".getBytes(StandardCharsets.UTF_8));
            strs.setSafe(6, "".getBytes(StandardCharsets.UTF_8));
            strs.setSafe(7, "asdf".getBytes(StandardCharsets.UTF_8));
          }
          assertThat(queryResult.getReader().getVectorSchemaRoot())
              .satisfiesAnyOf(
                  data -> assertRoot(data).isEqualTo(root32),
                  data -> assertRoot(data).isEqualTo(root64));
        }
      }
    }
  }