Java Code Examples for com.google.cloud.spanner.Value#timestamp()

The following examples show how to use com.google.cloud.spanner.Value#timestamp() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RandomValueGenerator.java    From DataflowTemplates with Apache License 2.0 6 votes vote down vote up
private Value generateScalar(Column column) {
  Type type = column.type();
  switch (type.getCode()) {
    case BOOL:
      return Value.bool(random.nextBoolean());
    case INT64:
      return Value.int64(random.nextLong());
    case FLOAT64:
      return Value.float64(random.nextDouble());
    case BYTES: {
      return Value.bytes(randomByteArray(column.size()));
    }
    case STRING: {
      return Value.string(randomString(column.size()));
    }
    case DATE: {
      return Value.date(randomDate());
    }
    case TIMESTAMP: {
      return Value.timestamp(randomTimestamp());
    }
  }
  throw new IllegalArgumentException("Unexpected type " + type);
}
 
Example 2
Source File: RandomValueGenerator.java    From DataflowTemplates with Apache License 2.0 5 votes vote down vote up
private Value generateNullValue(Type type) {
  switch (type.getCode()) {
    case BOOL:
      return Value.bool(null);
    case INT64:
      return Value.int64(null);
    case FLOAT64:
      return Value.float64(null);
    case BYTES:
      return Value.bytes(null);
    case STRING:
      return Value.string(null);
    case DATE:
      return Value.date(null);
    case TIMESTAMP:
      return Value.timestamp(null);
    case ARRAY:
      switch (type.getArrayElementType().getCode()) {
        case BOOL:
          return Value.boolArray((boolean[]) null);
        case INT64:
          return Value.int64Array((long[]) null);
        case FLOAT64:
          return Value.float64Array((double[]) null);
        case BYTES:
          return Value.bytesArray(null);
        case STRING:
          return Value.stringArray(null);
        case DATE:
          return Value.dateArray(null);
        case TIMESTAMP:
          return Value.timestampArray(null);
      }
  }
  throw new IllegalArgumentException("Unexpected type " + type);
}
 
Example 3
Source File: CloudSpannerResultSetMetaDataTest.java    From spanner-jdbc with MIT License 5 votes vote down vote up
private Value getDefaultValue(Type type, int row) {
  if (type == Type.bool())
    return Value.bool(Boolean.TRUE);
  if (type == Type.bytes())
    return Value.bytes(ByteArray.copyFrom("test byte array " + row));
  if (type == Type.date())
    return Value.date(com.google.cloud.Date.fromYearMonthDay(2018, 4, 1));
  if (type == Type.float64())
    return Value.float64(123.45D);
  if (type == Type.int64())
    return Value.int64(12345L);
  if (type == Type.string())
    return Value.string("test value " + row);
  if (type == Type.timestamp())
    return Value.timestamp(com.google.cloud.Timestamp.now());

  if (type.getCode() == Code.ARRAY && type.getArrayElementType() == Type.bool())
    return Value.boolArray(Arrays.asList(Boolean.TRUE, Boolean.FALSE));
  if (type.getCode() == Code.ARRAY && type.getArrayElementType() == Type.bytes())
    return Value.bytesArray(Arrays.asList(ByteArray.copyFrom("test byte array " + row),
        ByteArray.copyFrom("test byte array " + row)));
  if (type.getCode() == Code.ARRAY && type.getArrayElementType() == Type.date())
    return Value.dateArray(Arrays.asList(com.google.cloud.Date.fromYearMonthDay(2018, 4, 1),
        com.google.cloud.Date.fromYearMonthDay(2018, 4, 2)));
  if (type.getCode() == Code.ARRAY && type.getArrayElementType() == Type.float64())
    return Value.float64Array(Arrays.asList(123.45D, 543.21D));
  if (type.getCode() == Code.ARRAY && type.getArrayElementType() == Type.int64())
    return Value.int64Array(Arrays.asList(12345L, 54321L));
  if (type.getCode() == Code.ARRAY && type.getArrayElementType() == Type.string())
    return Value.stringArray(Arrays.asList("test value " + row, "test value " + row));
  if (type.getCode() == Code.ARRAY && type.getArrayElementType() == Type.timestamp())
    return Value.timestampArray(
        Arrays.asList(com.google.cloud.Timestamp.now(), com.google.cloud.Timestamp.now()));
  return null;
}