Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.datastore.v1.Key.PathElement;
import com.google.datastore.v1.PartitionId;
import com.google.datastore.v1.Value;
import com.google.datastore.v1.ArrayValue;
import com.google.protobuf.NullValue;
import com.google.protobuf.util.Timestamps;
import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -384,10 +385,34 @@ public static Value columnToValue(TableFieldSchema column, Object columnValue)
// 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);
switch (column.getMode()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add unit test coverage as well.

case "NULLABLE":
case "REQUIRED":
String strValue = columnValue.toString();
valueBuilder.setStringValue(strValue);
boolean excludeFromIndexes = strValue.getBytes().length > MAX_STRING_SIZE_BYTES;
valueBuilder.setExcludeFromIndexes(excludeFromIndexes);
break;

case "REPEATED":

ArrayValue.Builder arrayValueBuilder = ArrayValue.newBuilder();
boolean excludeArrayFromIndexes = false;

@SuppressWarnings("unchecked")
List<Object> objectList = (List<Object>) columnValue;
for (Object object: objectList) {
String arrayStringValue = object.toString();
if (arrayStringValue.getBytes().length > MAX_STRING_SIZE_BYTES) {
excludeArrayFromIndexes = true;
}
arrayValueBuilder.addValues(Value.newBuilder().setStringValue(arrayStringValue).build());
}
valueBuilder.setArrayValue(arrayValueBuilder.build());
valueBuilder.setExcludeFromIndexes(excludeArrayFromIndexes);
break;

}
break;
Comment on lines +388 to 416
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am reading this correctly, we are only handling REQUIRED and REPEATED fields for STRING types? Why not extend this to the other supported data types (INT64, FLOAT etc)?

case "INTEGER":
case "INT64":
Expand Down