Java Code Examples for com.google.datastore.v1.Value#Builder

The following examples show how to use com.google.datastore.v1.Value#Builder . 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: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 5 votes vote down vote up
/**
 * Make a list value containing the specified values.
 */
public static Value.Builder makeValue(Value value1, Value value2, Value... rest) {
  ArrayValue.Builder arrayValue = ArrayValue.newBuilder();
  arrayValue.addValues(value1);
  arrayValue.addValues(value2);
  arrayValue.addAllValues(Arrays.asList(rest));
  return Value.newBuilder().setArrayValue(arrayValue);
}
 
Example 2
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 5 votes vote down vote up
/**
 * Make an array value containing the specified values.
 */
public static Value.Builder makeValue(Value.Builder value1, Value.Builder value2,
    Value.Builder... rest) {
  ArrayValue.Builder arrayValue = ArrayValue.newBuilder();
  arrayValue.addValues(value1);
  arrayValue.addValues(value2);
  for (Value.Builder builder : rest) {
    arrayValue.addValues(builder);
  }
  return Value.newBuilder().setArrayValue(arrayValue);
}
 
Example 3
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 4 votes vote down vote up
/**
 * Make a boolean value.
 */
public static Value.Builder makeValue(boolean value) {
  return Value.newBuilder().setBooleanValue(value);
}
 
Example 4
Source File: DatastoreHelperTest.java    From google-cloud-datastore with Apache License 2.0 4 votes vote down vote up
private void assertTimestampToMilliseconds(long millis, long seconds, int nanos) {
  Value.Builder value = Value.newBuilder().setTimestampValue(Timestamp.newBuilder()
      .setSeconds(seconds)
      .setNanos(nanos));
  assertEquals(millis, DatastoreHelper.toDate(value.build()).getTime());
}
 
Example 5
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 4 votes vote down vote up
/**
 * Makes a GeoPoint value.
 */
public static Value.Builder makeValue(LatLng.Builder value) {
  return makeValue(value.build());
}
 
Example 6
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 4 votes vote down vote up
/**
 * Makes a GeoPoint value.
 */
public static Value.Builder makeValue(LatLng value) {
  return Value.newBuilder().setGeoPointValue(value);
}
 
Example 7
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 4 votes vote down vote up
/**
 * Make a timestamp value given a date.
 */
public static Value.Builder makeValue(Date date) {
  return Value.newBuilder().setTimestampValue(toTimestamp(date.getTime() * 1000L));
}
 
Example 8
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 4 votes vote down vote up
/**
 * Make a ByteString value.
 */
public static Value.Builder makeValue(ByteString blob) {
  return Value.newBuilder().setBlobValue(blob);
}
 
Example 9
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 4 votes vote down vote up
/**
 * Make a entity value.
 */
public static Value.Builder makeValue(Entity.Builder entity) {
  return makeValue(entity.build());
}
 
Example 10
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 4 votes vote down vote up
/**
 * Make an entity value.
 */
public static Value.Builder makeValue(Entity entity) {
  return Value.newBuilder().setEntityValue(entity);
}
 
Example 11
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 4 votes vote down vote up
/**
 * Make a string value.
 */
public static Value.Builder makeValue(String value) {
  return Value.newBuilder().setStringValue(value);
}
 
Example 12
Source File: BigQueryConverters.java    From DataflowTemplates with Apache License 2.0 4 votes vote down vote up
/**
 * Converts the value of a BigQuery column in Avro format into the value of a Datastore Entity
 * property.
 */
public static Value columnToValue(TableFieldSchema column, Object columnValue)
    throws IllegalArgumentException {
  String columnName = column.getName();
  if (columnValue == null) {
    return Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
  } else {
    Value.Builder valueBuilder = Value.newBuilder();
    switch (column.getType()) {
      case "STRING":
        // Datastore string properties greater than 1500 bytes will not be indexed in order to
        // respect the limit imposed on the maximum size of index-able string properties. See
        // https://cloud.google.com/datastore/docs/concepts/limits
        String strValue = columnValue.toString();
        valueBuilder.setStringValue(strValue);
        boolean excludeFromIndexes = strValue.getBytes().length > MAX_STRING_SIZE_BYTES;
        valueBuilder.setExcludeFromIndexes(excludeFromIndexes);
        break;
      case "INTEGER":
      case "INT64":
        valueBuilder.setIntegerValue((long) columnValue);
        break;
      case "FLOAT":
      case "FLOAT64":
        valueBuilder.setDoubleValue((double) columnValue);
        break;
      case "BOOLEAN":
      case "BOOL":
        valueBuilder.setBooleanValue((boolean) columnValue);
        break;
      case "TIMESTAMP":
        // Convert into milliseconds from the BigQuery timestamp, which is in micro seconds
        long timeInMillis = ((long) columnValue) / 1000;
        valueBuilder.setTimestampValue(Timestamps.fromMillis(timeInMillis));
        break;
      case "DATE":
      case "TIME":
      case "DATETIME":
        // Handle these types as STRING by default, no dedicated type exists in Datastore
        valueBuilder.setStringValue(columnValue.toString());
        break;
      default:
        // TODO: handle nested fields (types "RECORD" or "STRUCT")
        throw new IllegalArgumentException(
            String.format(
                "Column [%s] of type [%s] not supported.", column.getName(), column.getType()));
    }
    return valueBuilder.build();
  }
}
 
Example 13
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 4 votes vote down vote up
/**
 * Make a floating point value.
 */
public static Value.Builder makeValue(double value) {
  return Value.newBuilder().setDoubleValue(value);
}
 
Example 14
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 4 votes vote down vote up
/**
 * Make an integer value.
 */
public static Value.Builder makeValue(long key) {
  return Value.newBuilder().setIntegerValue(key);
}
 
Example 15
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 4 votes vote down vote up
/**
 * Make a key value.
 */
public static Value.Builder makeValue(Key.Builder key) {
  return makeValue(key.build());
}
 
Example 16
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 4 votes vote down vote up
/**
 * Make a key value.
 */
public static Value.Builder makeValue(Key key) {
  return Value.newBuilder().setKeyValue(key);
}
 
Example 17
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 4 votes vote down vote up
/**
 * Make an array value containing the specified values.
 */
public static Value.Builder makeValue(Iterable<Value> values) {
  return Value.newBuilder().setArrayValue(ArrayValue.newBuilder().addAllValues(values));
}
 
Example 18
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 4 votes vote down vote up
/**
 * Make a filter on a property for use in a query.
 */
public static Filter.Builder makeFilter(String property, PropertyFilter.Operator operator,
    Value.Builder value) {
  return makeFilter(property, operator, value.build());
}