private TimestampImpl(boolean isNull, boolean isCommitTimestamp, Timestamp value) { super(isNull, Type.timestamp(), value); this.isCommitTimestamp = isCommitTimestamp; }
private TimestampArrayImpl(boolean isNull, @Nullable List<Timestamp> values) { super(isNull, Type.timestamp(), values); }
@Override public Timestamp getTimestamp() { throw defaultGetter(Type.timestamp()); }
@Override Type newType() { return Type.timestamp(); } }.test();
@Override Type newElementType() { return Type.timestamp(); } }.test();
@Override public Timestamp getTimestamp() { checkType(Type.timestamp()); checkNotNull(); Preconditions.checkState(!isCommitTimestamp, "Commit timestamp value"); return value; }
@Override public Timestamp getTimestamp(int columnIndex) { checkNonNullOfType(columnIndex, Type.timestamp(), columnIndex); return getTimestampInternal(columnIndex); }
@Override public List<Timestamp> getTimestampArray() { throw defaultGetter(Type.array(Type.timestamp())); }
@Override public List<Timestamp> getTimestampList(int columnIndex) { checkNonNullOfType(columnIndex, Type.array(Type.timestamp()), columnIndex); return getTimestampListInternal(columnIndex); }
@Override public Timestamp getTimestamp(String columnName) { int columnIndex = getColumnIndex(columnName); checkNonNullOfType(columnIndex, Type.timestamp(), columnName); return getTimestampInternal(columnIndex); }
@Override public List<Timestamp> getTimestampList(String columnName) { int columnIndex = getColumnIndex(columnName); checkNonNullOfType(columnIndex, Type.array(Type.timestamp()), columnName); return getTimestampListInternal(columnIndex); }
@Test public void timestamp() { String timestamp = "2016-09-15T00:00:00Z"; Timestamp t = Timestamp.parseTimestamp(timestamp); Value v = Value.timestamp(t); assertThat(v.getType()).isEqualTo(Type.timestamp()); assertThat(v.isNull()).isFalse(); assertThat(v.isCommitTimestamp()).isFalse(); assertThat(v.getTimestamp()).isSameAs(t); assertThat(v.toString()).isEqualTo(timestamp); }
@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 bindTimestampNull() { Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").to((Timestamp) null), Type.timestamp()); assertThat(row.isNull(0)).isTrue(); }
@Test public void timestampNull() { Value v = Value.timestamp(null); assertThat(v.getType()).isEqualTo(Type.timestamp()); assertThat(v.isNull()).isTrue(); assertThat(v.toString()).isEqualTo(NULL_STRING); assertThat(v.isCommitTimestamp()).isFalse(); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("null value"); v.getTimestamp(); }
@Test public void bindTimestamp() { Timestamp t = Timestamp.parseTimestamp("2016-09-18T00:00:00Z"); Struct row = execute(Statement.newBuilder("SELECT @v").bind("v").to(t), Type.timestamp()); assertThat(row.isNull(0)).isFalse(); assertThat(row.getTimestamp(0)).isEqualTo(t); }
@Test public void bindTimestampArrayNull() { Struct row = execute( Statement.newBuilder("SELECT @v").bind("v").toTimestampArray(null), Type.array(Type.timestamp())); assertThat(row.isNull(0)).isTrue(); }
@Test public void bindTimestampArray() { Timestamp t1 = Timestamp.parseTimestamp("2016-09-18T00:00:00Z"); Timestamp t2 = Timestamp.parseTimestamp("2016-09-19T00:00:00Z"); Struct row = execute( Statement.newBuilder("SELECT @v").bind("v").toTimestampArray(asList(t1, t2, null)), Type.array(Type.timestamp())); assertThat(row.isNull(0)).isFalse(); assertThat(row.getTimestampList(0)).containsExactly(t1, t2, null).inOrder(); }
@Test public void getTimestampList() { List<Timestamp> timestampList = new ArrayList<>(); timestampList.add(Timestamp.parseTimestamp("0001-01-01T00:00:00Z")); timestampList.add(Timestamp.parseTimestamp("0002-02-02T02:00:00Z")); consumer.onPartialResultSet( PartialResultSet.newBuilder() .setMetadata( makeMetadata(Type.struct(Type.StructField.of("f", Type.array(Type.timestamp()))))) .addValues(Value.timestampArray(timestampList).toProto()) .build()); consumer.onCompleted(); assertThat(resultSet.next()).isTrue(); assertThat(resultSet.getTimestampList(0)).isEqualTo(timestampList); }
@Test public void getTimestamp() { consumer.onPartialResultSet( PartialResultSet.newBuilder() .setMetadata(makeMetadata(Type.struct(Type.StructField.of("f", Type.timestamp())))) .addValues(Value.timestamp(Timestamp.parseTimestamp("0001-01-01T00:00:00Z")).toProto()) .build()); consumer.onCompleted(); assertThat(resultSet.next()).isTrue(); assertThat(resultSet.getTimestamp(0)) .isEqualTo(Timestamp.parseTimestamp("0001-01-01T00:00:00Z")); }