final com.google.datastore.v1.Entity toPb() { com.google.datastore.v1.Entity.Builder entityPb = com.google.datastore.v1.Entity.newBuilder(); for (Map.Entry<String, Value<?>> entry : properties.entrySet()) { entityPb.putProperties(entry.getKey(), entry.getValue().toPb()); } if (key != null) { entityPb.setKey(key.toPb()); } return entityPb.build(); } }
/** * Convert TableRow to Entity * * @param row TableRow of bigquery * @return converted Entity * @throws ParseException */ public Entity convertTableRowToEntity(TableRow row) throws ParseException { String keyName = row.get(keyColumn).toString(); Key key = getKey(keyName); Entity.Builder builder = Entity.newBuilder().setKey(key); Set<Map.Entry<String, Object>> entries = row.entrySet(); for (Map.Entry<String, Object> entry : entries) { // Skip on the key column if (entry.getKey().equals(keyColumn)) { continue; } // Put a value in the builder String propertyName = entry.getKey(); Object value = entry.getValue(); Value v = convertToDatastoreValue(propertyName, value); if (v != null) { builder.putProperties(propertyName, v); } } return builder.build(); }
final com.google.datastore.v1.Entity toPb() { com.google.datastore.v1.Entity.Builder entityPb = com.google.datastore.v1.Entity.newBuilder(); for (Map.Entry<String, Value<?>> entry : properties.entrySet()) { entityPb.putProperties(entry.getKey(), entry.getValue().toPb()); } if (key != null) { entityPb.setKey(key.toPb()); } return entityPb.build(); } }
Value subV = convertToDatastoreValue(columnName, struct.get(subKey)); if (subV != null) { subEntityBuilder.putProperties(subKey, subV);
/** * Build an entity for the given ancestorKey, kind, namespace and value. * * @param largePropertySize if greater than 0, add an unindexed property of the given size. */ static Entity makeEntity( Long value, Key ancestorKey, String kind, @Nullable String namespace, int largePropertySize) { Entity.Builder entityBuilder = Entity.newBuilder(); Key.Builder keyBuilder = makeKey(ancestorKey, kind, UUID.randomUUID().toString()); // NOTE: Namespace is not inherited between keys created with DatastoreHelper.makeKey, so // we must set the namespace on keyBuilder. TODO: Once partitionId inheritance is added, // we can simplify this code. if (namespace != null) { keyBuilder.getPartitionIdBuilder().setNamespaceId(namespace); } entityBuilder.setKey(keyBuilder.build()); entityBuilder.putProperties("value", makeValue(value).build()); if (largePropertySize > 0) { entityBuilder.putProperties( "unindexed_value", makeValue(new String(new char[largePropertySize]).replace("\0", "A")) .setExcludeFromIndexes(true) .build()); } return entityBuilder.build(); }
/** Builds a response of the given timestamp. */ private static RunQueryResponse makeLatestTimestampResponse(long timestamp) { RunQueryResponse.Builder timestampResponse = RunQueryResponse.newBuilder(); Entity.Builder entity = Entity.newBuilder(); entity.setKey(makeKey("dummyKind", "dummyId")); entity.putProperties("timestamp", makeValue(new Date(timestamp * 1000)).build()); EntityResult.Builder entityResult = EntityResult.newBuilder(); entityResult.setEntity(entity); QueryResultBatch.Builder batch = QueryResultBatch.newBuilder(); batch.addEntityResults(entityResult); timestampResponse.setBatch(batch); return timestampResponse.build(); }
/** Builds a per-kind statistics response with the given entity size. */ private static RunQueryResponse makeStatKindResponse(long entitySizeInBytes) { RunQueryResponse.Builder statKindResponse = RunQueryResponse.newBuilder(); Entity.Builder entity = Entity.newBuilder(); entity.setKey(makeKey("dummyKind", "dummyId")); entity.putProperties("entity_bytes", makeValue(entitySizeInBytes).build()); EntityResult.Builder entityResult = EntityResult.newBuilder(); entityResult.setEntity(entity); QueryResultBatch.Builder batch = QueryResultBatch.newBuilder(); batch.addEntityResults(entityResult); statKindResponse.setBatch(batch); return statKindResponse.build(); }