@Test public void writeInt64Null() { write(baseInsert().set("Int64Value").to((Long) null).build()); Struct row = readLastRow("Int64Value"); assertThat(row.isNull(0)).isTrue(); }
@Test public void writeBoolArrayNoNulls() { write(baseInsert().set("BoolArrayValue").toBoolArray(Arrays.asList(true, false)).build()); Struct row = readLastRow("BoolArrayValue"); assertThat(row.isNull(0)).isFalse(); assertThat(row.getBooleanArray(0)).isEqualTo(new boolean[] {true, false}); }
@Test public void bindBytesArrayEmpty() { Struct row = execute( Statement.newBuilder("SELECT @v").bind("v").toBytesArray(Arrays.<ByteArray>asList()), Type.array(Type.bytes())); assertThat(row.isNull(0)).isFalse(); assertThat(row.getBytesList(0)).isEmpty(); }
Object value = rowData.get(i); Type fieldType = field.getType(); switch (fieldType.getCode()) { case BOOL: builder.set(fieldName).to((Boolean) value); break; case INT64: builder.set(fieldName).to((Long) value); break; case FLOAT64: builder.set(fieldName).to((Double) value); break; case STRING: builder.set(fieldName).to((String) value); break; case BYTES: builder.set(fieldName).to((ByteArray) value); break; case TIMESTAMP: builder.set(fieldName).to((Timestamp) value); break; case DATE: builder.set(fieldName).to((Date) value); break; case ARRAY: switch (fieldType.getArrayElementType().getCode()) { case BOOL: builder.set(fieldName).toBoolArray((Iterable<Boolean>) value); break;
@Test public void structArrayFieldNull() { Type elementType = Type.struct( Arrays.asList( Type.StructField.of("ff1", Type.string()), Type.StructField.of("ff2", Type.int64()))); Struct struct = Struct.newBuilder().set("f1").to("x").set("f2").toStructArray(elementType, null).build(); assertThat(struct.getType()) .isEqualTo( Type.struct( Type.StructField.of("f1", Type.string()), Type.StructField.of("f2", Type.array(elementType)))); assertThat(struct.isNull(0)).isFalse(); assertThat(struct.isNull(1)).isTrue(); }
@Test public void structWithArrayOfStructField() { Type elementType = Type.struct( Arrays.asList( Type.StructField.of("ff1", Type.string()), Type.StructField.of("ff2", Type.int64()))); List<Struct> arrayElements = Arrays.asList( Struct.newBuilder().set("ff1").to("v1").set("ff2").to(1).build(), Struct.newBuilder().set("ff1").to("v1").set("ff2").to(1).build()); Struct struct = Struct.newBuilder() .set("f1") .to("x") .set("f2") .toStructArray(elementType, arrayElements) .build(); assertThat(struct.getType()) .isEqualTo( Type.struct( Type.StructField.of("f1", Type.string()), Type.StructField.of("f2", Type.array(elementType)))); assertThat(struct.isNull(0)).isFalse(); assertThat(struct.isNull(1)).isFalse(); assertThat(struct.getString(0)).isEqualTo("x"); assertThat(struct.getStructList(1)).isEqualTo(arrayElements); }
@Test public void writeBool() { write(baseInsert().set("BoolValue").to(true).build()); Struct row = readLastRow("BoolValue"); assertThat(row.isNull(0)).isFalse(); assertThat(row.getBoolean(0)).isTrue(); }
@Test public void writeInt64ArrayNoNulls() { write(baseInsert().set("Int64ArrayValue").toInt64Array(Arrays.asList(1L, 2L)).build()); Struct row = readLastRow("Int64ArrayValue"); assertThat(row.isNull(0)).isFalse(); assertThat(row.getLongArray(0)).isEqualTo(new long[] {1, 2}); }
@Test public void writeFloat64ArrayEmpty() { write(baseInsert().set("Float64ArrayValue").toFloat64Array(new double[] {}).build()); Struct row = readLastRow("Float64ArrayValue"); assertThat(row.isNull(0)).isFalse(); assertThat(row.getDoubleList(0)).containsExactly(); }
@Test public void bindStringArrayEmpty() { Struct row = execute( Statement.newBuilder("SELECT @v").bind("v").toStringArray(Arrays.<String>asList()), Type.array(Type.string())); assertThat(row.isNull(0)).isFalse(); assertThat(row.getStringList(0)).containsExactly(); }
@Test public void bindInt64ArrayEmpty() { Struct row = execute( Statement.newBuilder("SELECT @v").bind("v").toInt64Array(Arrays.<Long>asList()), Type.array(Type.int64())); assertThat(row.isNull(0)).isFalse(); assertThat(row.getLongList(0)).containsExactly(); }
@Test public void bindFloat64ArrayEmpty() { Struct row = execute( Statement.newBuilder("SELECT @v").bind("v").toFloat64Array(Arrays.<Double>asList()), Type.array(Type.float64())); assertThat(row.isNull(0)).isFalse(); assertThat(row.getDoubleList(0)).containsExactly(); }
@Test public void bindTimestampArrayEmpty() { Struct row = execute( Statement.newBuilder("SELECT @v") .bind("v") .toTimestampArray(Arrays.<Timestamp>asList()), Type.array(Type.timestamp())); assertThat(row.isNull(0)).isFalse(); assertThat(row.getTimestampList(0)).containsExactly(); }
@Test public void bindDateArrayEmpty() { Struct row = execute( Statement.newBuilder("SELECT @v").bind("v").toDateArray(Arrays.<Date>asList()), Type.array(Type.date())); assertThat(row.isNull(0)).isFalse(); assertThat(row.getDateList(0)).containsExactly(); }
@Test public void bindBoolArrayEmpty() { Struct row = execute( Statement.newBuilder("SELECT @v").bind("v").toBoolArray(Arrays.<Boolean>asList()), Type.array(Type.bool())); assertThat(row.isNull(0)).isFalse(); assertThat(row.getBooleanList(0)).containsExactly(); }
@Test public void writeBytesArrayEmpty() { write(baseInsert().set("BytesArrayValue").toBytesArray(Arrays.<ByteArray>asList()).build()); Struct row = readLastRow("BytesArrayValue"); assertThat(row.isNull(0)).isFalse(); assertThat(row.getBytesList(0)).containsExactly(); }
@Test public void writeDateArrayEmpty() { write(baseInsert().set("DateArrayValue").toDateArray(Arrays.<Date>asList()).build()); Struct row = readLastRow("DateArrayValue"); assertThat(row.isNull(0)).isFalse(); assertThat(row.getDateList(0)).containsExactly(); }
@Test public void writeTimestampArrayEmpty() { write( baseInsert() .set("TimestampArrayValue") .toTimestampArray(Arrays.<Timestamp>asList()) .build()); Struct row = readLastRow("TimestampArrayValue"); assertThat(row.isNull(0)).isFalse(); assertThat(row.getTimestampList(0)).containsExactly(); }
@Test public void writeStringArrayEmpty() { write(baseInsert().set("StringArrayValue").toStringArray(Arrays.<String>asList()).build()); Struct row = readLastRow("StringArrayValue"); assertThat(row.isNull(0)).isFalse(); assertThat(row.getStringList(0)).containsExactly(); }
@Test public void writeBytesArrayNull() { write(baseInsert().set("BytesArrayValue").toBytesArray(null).build()); Struct row = readLastRow("BytesArrayValue"); assertThat(row.isNull(0)).isTrue(); }