本文整理汇总了Java中com.google.datastore.v1.Entity类的典型用法代码示例。如果您正苦于以下问题:Java Entity类的具体用法?Java Entity怎么用?Java Entity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Entity类属于com.google.datastore.v1包,在下文中一共展示了Entity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toTableRow
import com.google.datastore.v1.Entity; //导入依赖的package包/类
private TableRow toTableRow(List<TableFieldSchema> tableSchema, Entity e) throws IOException {
TableRow row = new TableRow();
Map<String, Value> fields = e.getPropertiesMap();
for (TableFieldSchema columnSchema : tableSchema) {
if (columnSchema.getName().equals("__key__") && columnSchema.getType().toUpperCase().equals("STRING")) {
row.put(columnSchema.getName(), keyToString(e.getKey()));
}
else if (fields.containsKey(columnSchema.getName())) {
Value v = fields.get(columnSchema.getName());
row.put(columnSchema.getName(), toRowValue(columnSchema, v));
}
}
return row;
}
示例2: main
import com.google.datastore.v1.Entity; //导入依赖的package包/类
public static void main(String[] args) {
BigQueryToDatastoreOptions options = PipelineOptionsFactory.fromArgs(args).withValidation()
.as(BigQueryToDatastoreOptions.class);
String inputTable = options.getInputTable().get();
String projectID = options.getOutputProjectID().get();
String kind = options.getOutputKind().get();
LOG.info("Input_Table : " + inputTable);
LOG.info("ProjectID : " + projectID);
LOG.info("Kind : " + kind);
Pipeline p = Pipeline.create(options);
PCollection<KV<Integer, Iterable<TableRow>>> keywordGroups = p
.apply(BigQueryIO.Read.named("ReadUtterance").from(inputTable)).apply(new GroupKeywords());
CreateEntities createEntities = new CreateEntities();
createEntities.setKind(kind);
PCollection<Entity> entities = keywordGroups.apply(createEntities);
entities.apply(DatastoreIO.v1().write().withProjectId(projectID));
p.run();
}
示例3: processElement
import com.google.datastore.v1.Entity; //导入依赖的package包/类
@ProcessElement
public void processElement(ProcessContext c) {
Entity.Builder entityBuilder = Entity.newBuilder();
Key key = makeKey(makeKey(kind, ancestorKey).build(), kind, c.element().getKey()).build();
entityBuilder.setKey(key);
List<Value> candidates = new ArrayList<>();
Map<String, Value> properties = new HashMap<>();
for (CompletionCandidate tag : c.element().getValue()) {
Entity.Builder tagEntity = Entity.newBuilder();
properties.put("tag", makeValue(tag.value).build());
properties.put("count", makeValue(tag.count).build());
candidates.add(makeValue(tagEntity).build());
}
properties.put("candidates", makeValue(candidates).build());
entityBuilder.putAllProperties(properties);
c.output(entityBuilder.build());
}
示例4: processElement
import com.google.datastore.v1.Entity; //导入依赖的package包/类
@ProcessElement
public void processElement(ProcessContext c) throws Exception {
Entity entity = c.element();
EntityBQTransform ebt = EntityBQTransform.newBuilder()
.setRowSchema(tableSchema().getFields())
.setStrictCast(strictCast().get())
.build();
TableRow row = ebt.toTableRow(entity);
if (jsTransform().hasTransform()) {
String rowJson = jsTransform().invoke(
Transport.getJsonFactory().toString(entity),
Transport.getJsonFactory().toString(row));
row = Transport.getJsonFactory().fromString(rowJson, TableRow.class);
}
c.output(row);
}
示例5: processElement
import com.google.datastore.v1.Entity; //导入依赖的package包/类
@ProcessElement
public void processElement(ProcessContext c) throws Exception {
String entityJson = c.element();
if (getJSTransform().hasTransform()) {
entityJson = getJSTransform().invoke(entityJson);
}
Entity.Builder builder = Entity.newBuilder();
getJsonParser().merge(entityJson, builder);
Entity entity = builder.build();
// Remove old project id reference from key
Key k = entity.getKey();
builder.setKey(Key.newBuilder()
.addAllPath(k.getPathList())
.setPartitionId(PartitionId.newBuilder()
.setNamespaceId(k.getPartitionId().getNamespaceId()))
.build());
c.output(builder.build());
}
示例6: testDatastoreToGcs_EntityToJson_noTransform
import com.google.datastore.v1.Entity; //导入依赖的package包/类
@Test
public void testDatastoreToGcs_EntityToJson_noTransform() throws Exception {
DoFnTester<Entity, String> fnTester = DoFnTester.of(EntityToJson.newBuilder()
.setJsTransformPath(StaticValueProvider.of(null))
.setJsTransformFunctionName(StaticValueProvider.of(null))
.build());
Builder entityBuilder = Entity.newBuilder();
JsonFormat.parser().usingTypeRegistry(
TypeRegistry.newBuilder()
.add(Entity.getDescriptor())
.build())
.merge(mEntityJson, entityBuilder);
Entity entity = entityBuilder.build();
List<String> entityJsonOutputs = fnTester.processBundle(entity);
Assert.assertEquals(mEntityJson, entityJsonOutputs.get(0));
}
示例7: testDatastoreToGcs_EntityToJson_withTransform
import com.google.datastore.v1.Entity; //导入依赖的package包/类
@Test
public void testDatastoreToGcs_EntityToJson_withTransform() throws Exception {
DoFnTester<Entity, String> fnTester = DoFnTester.of(EntityToJson.newBuilder()
.setJsTransformPath(StaticValueProvider.of(jsTransformPath))
.setJsTransformFunctionName(StaticValueProvider.of("transform"))
.build());
Builder entityBuilder = Entity.newBuilder();
JsonFormat.parser().usingTypeRegistry(
TypeRegistry.newBuilder()
.add(Entity.getDescriptor())
.build())
.merge(mEntityJson, entityBuilder);
Entity entity = entityBuilder.build();
List<String> entityJsonOutputs = fnTester.processBundle(entity);
Assert.assertEquals(mTransformedEntityJson, entityJsonOutputs.get(0));
}
示例8: testGcsToDatastore_EntityToJson_noTransform
import com.google.datastore.v1.Entity; //导入依赖的package包/类
@Test
public void testGcsToDatastore_EntityToJson_noTransform() throws Exception {
DoFnTester<String, Entity> fnTester = DoFnTester.of(JsonToEntity.newBuilder()
.setJsTransformPath(StaticValueProvider.of(null))
.setJsTransformFunctionName(StaticValueProvider.of(null))
.build());
List<Entity> output = fnTester.processBundle(mEntityJson);
Entity outputEntity = output.get(0);
Printer printer = JsonFormat.printer()
.omittingInsignificantWhitespace()
.usingTypeRegistry(
TypeRegistry.newBuilder()
.add(Entity.getDescriptor())
.build());
Assert.assertEquals(mEntityJson, printer.print(outputEntity));
}
示例9: testEntityBQTransform_toTableRow_timestamp
import com.google.datastore.v1.Entity; //导入依赖的package包/类
@Test
public void testEntityBQTransform_toTableRow_timestamp() throws IOException {
Entity e;
EntityBQTransform strictEbt = EntityBQTransform.newBuilder()
.setStrictCast(true)
.setRowSchema(exampleTable().getFields())
.build();
EntityBQTransform nonstrictEbt = EntityBQTransform.newBuilder()
.setStrictCast(false)
.setRowSchema(exampleTable().getFields())
.build();
e = Entity.newBuilder()
.putProperties("birthTimestamp", Value.newBuilder().setTimestampValue(
Timestamp.newBuilder().setNanos(1000).setSeconds(1498692500).build()).build())
.build();
Assert.assertEquals("2017-06-28T23:28:20.000001Z", strictEbt.toTableRow(e).get("birthTimestamp"));
Assert.assertEquals("2017-06-28T23:28:20.000001Z", nonstrictEbt.toTableRow(e).get("birthTimestamp"));
}
示例10: testEntityBQTransform_toTableRow_date
import com.google.datastore.v1.Entity; //导入依赖的package包/类
@Test
public void testEntityBQTransform_toTableRow_date() throws IOException {
Entity e;
EntityBQTransform strictEbt = EntityBQTransform.newBuilder()
.setStrictCast(true)
.setRowSchema(exampleTable().getFields())
.build();
EntityBQTransform nonstrictEbt = EntityBQTransform.newBuilder()
.setStrictCast(false)
.setRowSchema(exampleTable().getFields())
.build();
e = Entity.newBuilder()
.putProperties("birthDate", Value.newBuilder().setTimestampValue(
Timestamp.newBuilder().setNanos(1000).setSeconds(1498692500).build()).build())
.build();
Assert.assertEquals("2017-06-28", strictEbt.toTableRow(e).get("birthDate"));
Assert.assertEquals("2017-06-28", nonstrictEbt.toTableRow(e).get("birthDate"));
}
示例11: testEntityBQTransform_toTableRow_time
import com.google.datastore.v1.Entity; //导入依赖的package包/类
@Test
public void testEntityBQTransform_toTableRow_time() throws IOException {
Entity e;
EntityBQTransform strictEbt = EntityBQTransform.newBuilder()
.setStrictCast(true)
.setRowSchema(exampleTable().getFields())
.build();
EntityBQTransform nonstrictEbt = EntityBQTransform.newBuilder()
.setStrictCast(false)
.setRowSchema(exampleTable().getFields())
.build();
e = Entity.newBuilder()
.putProperties("birthTime", Value.newBuilder().setTimestampValue(
Timestamp.newBuilder().setNanos(1000).setSeconds(1498692500).build()).build())
.build();
Assert.assertEquals("23:28:20.000001", strictEbt.toTableRow(e).get("birthTime"));
Assert.assertEquals("23:28:20.000001", nonstrictEbt.toTableRow(e).get("birthTime"));
}
示例12: testEntityBQTransform_toTableRow_datetime
import com.google.datastore.v1.Entity; //导入依赖的package包/类
@Test
public void testEntityBQTransform_toTableRow_datetime() throws IOException {
Entity e;
EntityBQTransform strictEbt = EntityBQTransform.newBuilder()
.setStrictCast(true)
.setRowSchema(exampleTable().getFields())
.build();
EntityBQTransform nonstrictEbt = EntityBQTransform.newBuilder()
.setStrictCast(false)
.setRowSchema(exampleTable().getFields())
.build();
e = Entity.newBuilder()
.putProperties("birthDateTime", Value.newBuilder().setTimestampValue(
Timestamp.newBuilder().setNanos(1000).setSeconds(1498692500).build()).build())
.build();
Assert.assertEquals("2017-06-28 23:28:20.000001", strictEbt.toTableRow(e).get("birthDateTime"));
Assert.assertEquals("2017-06-28 23:28:20.000001", nonstrictEbt.toTableRow(e).get("birthDateTime"));
}
示例13: testDatastoreToBq_EntityToTableRow_notransform
import com.google.datastore.v1.Entity; //导入依赖的package包/类
@Test
public void testDatastoreToBq_EntityToTableRow_notransform() throws Exception, IOException {
DoFnTester<Entity, TableRow> fnTester = DoFnTester.of(EntityToTableRow.newBuilder()
.setStrictCast(StaticValueProvider.of(true))
.setTableSchemaJson(StaticValueProvider.of(mTableSchemaJson))
.setJsTransformFunctionName(StaticValueProvider.of(null))
.setJsTransformPath(StaticValueProvider.of(null))
.build());
Builder entityBuilder = Entity.newBuilder();
JsonFormat.parser().usingTypeRegistry(
TypeRegistry.newBuilder()
.add(Entity.getDescriptor())
.build())
.merge(mEntityJson, entityBuilder);
Entity entity = entityBuilder.build();
List<TableRow> tableRows = fnTester.processBundle(entity);
TableRow tr = tableRows.get(0);
Assert.assertEquals(1, tableRows.size());
Assert.assertEquals("key(Drawing, '31ce830e-91d0-405e-855a-abe416cadc1f')", tr.get("__key__"));
Assert.assertEquals("79a1d9d9-e255-427a-9b09-f45157e97790", tr.get("canvasId"));
}
示例14: processElement
import com.google.datastore.v1.Entity; //导入依赖的package包/类
@Override
public void processElement(ProcessContext c) {
String[] columns = c.element().split(",");
Builder builder = Key.newBuilder();
PathElement pathElement = builder.addPathBuilder().setKind("Product").setName(columns[0]).build();
Key key = builder.setPath(0, pathElement).build();
Entity.Builder entityBuilder = Entity.newBuilder();
entityBuilder.setKey(key);
entityBuilder.getMutableProperties().put("ProductCode", makeValue(columns[0]).build());
entityBuilder.getMutableProperties().put("CategoryCode", makeValue(columns[1]).build());
entityBuilder.getMutableProperties().put("ProductName", makeValue(columns[2]).build());
entityBuilder.getMutableProperties().put("Price", makeValue(Integer.valueOf(columns[3])).build());
String imageURL = "";
if (columns.length > 4) {
imageURL = columns[4];
}
entityBuilder.getMutableProperties().put("ImageURL", makeValue(imageURL).build());
Entity entity = entityBuilder.build();
c.output(entity);
}
示例15: queryLatestStatisticsTimestamp
import com.google.datastore.v1.Entity; //导入依赖的package包/类
/**
* Cloud Datastore system tables with statistics are periodically updated. This method fetches
* the latest timestamp (in microseconds) of statistics update using the {@code __Stat_Total__}
* table.
*/
private static long queryLatestStatisticsTimestamp(Datastore datastore,
@Nullable String namespace) throws DatastoreException {
Query.Builder query = Query.newBuilder();
// Note: namespace either being null or empty represents the default namespace, in which
// case we treat it as not provided by the user.
if (Strings.isNullOrEmpty(namespace)) {
query.addKindBuilder().setName("__Stat_Total__");
} else {
query.addKindBuilder().setName("__Stat_Ns_Total__");
}
query.addOrder(makeOrder("timestamp", DESCENDING));
query.setLimit(Int32Value.newBuilder().setValue(1));
RunQueryRequest request = makeRequest(query.build(), namespace);
RunQueryResponse response = datastore.runQuery(request);
QueryResultBatch batch = response.getBatch();
if (batch.getEntityResultsCount() == 0) {
throw new NoSuchElementException(
"Datastore total statistics unavailable");
}
Entity entity = batch.getEntityResults(0).getEntity();
return entity.getProperties().get("timestamp").getTimestampValue().getSeconds() * 1000000;
}