@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 writeFloat64ArrayNull() { write(baseInsert().set("Float64ArrayValue").toFloat64Array((double[]) null).build()); Struct row = readLastRow("Float64ArrayValue"); assertThat(row.isNull(0)).isTrue(); }
@Test public void writeFloat64ArrayNoNulls() { write(baseInsert().set("Float64ArrayValue").toFloat64Array(Arrays.asList(1.0, 2.0)).build()); Struct row = readLastRow("Float64ArrayValue"); assertThat(row.isNull(0)).isFalse(); assertThat(row.getDoubleArray(0).length).isEqualTo(2); assertThat(row.getDoubleArray(0)[0]).isWithin(0.0).of(1.0); assertThat(row.getDoubleArray(0)[1]).isWithin(0.0).of(2.0); }
@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 bindFloat64ArrayNull() { Struct row = execute( Statement.newBuilder("SELECT @v").bind("v").toFloat64Array((double[]) null), Type.array(Type.float64())); assertThat(row.isNull(0)).isTrue(); }
@Test public void writeFloat64Array() { write( baseInsert() .set("Float64ArrayValue") .toFloat64Array(Arrays.asList(null, 1.0, 2.0)) .build()); Struct row = readLastRow("Float64ArrayValue"); assertThat(row.isNull(0)).isFalse(); assertThat(row.getDoubleList(0)).containsExactly(null, 1.0, 2.0).inOrder(); expectedException.expect(NullPointerException.class); row.getDoubleArray(0); }
@Test public void bindFloat64Array() { Struct row = execute( Statement.newBuilder("SELECT @v") .bind("v") .toFloat64Array( asList( null, 1.0, 2.0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.NaN)), Type.array(Type.float64())); assertThat(row.isNull(0)).isFalse(); assertThat(row.getDoubleList(0)) .containsExactly( null, 1.0, 2.0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.NaN) .inOrder(); }
break; case FLOAT64: builder.set(fieldName).toFloat64Array((Iterable<Double>) value); break; case STRING:
.toInt64Array((long[]) null) .set("floatArr") .toFloat64Array(new double[] {1.1, 2.2, 3.3}) .set("floatArrNull") .toFloat64Array((double[]) null) .set("nullStr") .to((String) null)
builder .set(column.name()) .toFloat64Array(readFloat64Array(record, arrayType, fieldName).orElse(null)); break; case STRING:
@Test public void nullPrimitiveArrays() throws Exception { Mutation int64 = Mutation.newInsertOrUpdateBuilder("test").set("one").toInt64Array((long[]) null).build(); Mutation float64 = Mutation.newInsertOrUpdateBuilder("test") .set("one") .toFloat64Array((double[]) null) .build(); Mutation bool = Mutation.newInsertOrUpdateBuilder("test").set("one").toBoolArray((boolean[]) null).build(); assertThat(MutationSizeEstimator.sizeOf(int64), is(0L)); assertThat(MutationSizeEstimator.sizeOf(float64), is(0L)); assertThat(MutationSizeEstimator.sizeOf(bool), is(0L)); }
@Test public void primitiveArrays() throws Exception { Mutation int64 = Mutation.newInsertOrUpdateBuilder("test") .set("one") .toInt64Array(new long[] {1L, 2L, 3L}) .build(); Mutation float64 = Mutation.newInsertOrUpdateBuilder("test") .set("one") .toFloat64Array(new double[] {1., 2.}) .build(); Mutation bool = Mutation.newInsertOrUpdateBuilder("test") .set("one") .toBoolArray(new boolean[] {true, true, false, true}) .build(); assertThat(MutationSizeEstimator.sizeOf(int64), is(24L)); assertThat(MutationSizeEstimator.sizeOf(float64), is(16L)); assertThat(MutationSizeEstimator.sizeOf(bool), is(4L)); }
break; case FLOAT64: builder.set(fieldName).toFloat64Array((Iterable<Double>) value); break; case STRING: