本文整理汇总了Java中com.google.datastore.v1.Entity类的典型用法代码示例。如果您正苦于以下问题:Java Entity类的具体用法?Java Entity怎么用?Java Entity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Entity类属于com.google.datastore.v1包,在下文中一共展示了Entity类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:cobookman,项目名称:teleport,代码行数:17,代码来源:EntityBQTransform.java
示例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();
}
开发者ID:sinmetal,项目名称:iron-hippo,代码行数:26,代码来源:BigQueryToDatastore.java
示例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());
}
开发者ID:apache,项目名称:beam,代码行数:19,代码来源:AutoComplete.java
示例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);
}
开发者ID:cobookman,项目名称:teleport,代码行数:20,代码来源:DatastoreToBq.java
示例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());
}
开发者ID:cobookman,项目名称:teleport,代码行数:22,代码来源:GcsToDatastore.java
示例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));
}
开发者ID:cobookman,项目名称:teleport,代码行数:19,代码来源:DatastoreToGcsTest.java
示例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));
}
开发者ID:cobookman,项目名称:teleport,代码行数:19,代码来源:DatastoreToGcsTest.java
示例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));
}
开发者ID:cobookman,项目名称:teleport,代码行数:18,代码来源:GcsToDatastoreTest.java
示例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"));
}
开发者ID:cobookman,项目名称:teleport,代码行数:23,代码来源:EntityBQTransformTest.java
示例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"));
}
开发者ID:cobookman,项目名称:teleport,代码行数:23,代码来源:EntityBQTransformTest.java
示例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"));
}
开发者ID:cobookman,项目名称:teleport,代码行数:23,代码来源:EntityBQTransformTest.java
示例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"));
}
开发者ID:cobookman,项目名称:teleport,代码行数:23,代码来源:EntityBQTransformTest.java
示例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"));
}
开发者ID:cobookman,项目名称:teleport,代码行数:25,代码来源:DatastoreToBqTest.java
示例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);
}
开发者ID:topgate,项目名称:retail-demo,代码行数:24,代码来源:StorageToDatastore.java
示例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;
}
开发者ID:apache,项目名称:beam,代码行数:29,代码来源:DatastoreV1.java
示例16: testE2EV1Read
import com.google.datastore.v1.Entity; //导入依赖的package包/类
/**
* An end-to-end test for {@link DatastoreV1.Read#withQuery(Query)}
*
* <p>Write some test entities to datastore and then run a pipeline that
* reads and counts the total number of entities. Verify that the count matches the
* number of entities written.
*/
@Test
public void testE2EV1Read() throws Exception {
// Read from datastore
Query query = V1TestUtil.makeAncestorKindQuery(
options.getKind(), options.getNamespace(), ancestor);
DatastoreV1.Read read = DatastoreIO.v1().read()
.withProjectId(project)
.withQuery(query)
.withNamespace(options.getNamespace());
// Count the total number of entities
Pipeline p = Pipeline.create(options);
PCollection<Long> count = p
.apply(read)
.apply(Count.<Entity>globally());
PAssert.thatSingleton(count).isEqualTo(numEntities);
p.run();
}
开发者ID:apache,项目名称:beam,代码行数:28,代码来源:V1ReadIT.java
示例17: testE2EV1ReadWithGQLQuery
import com.google.datastore.v1.Entity; //导入依赖的package包/类
/**
* An end-to-end test for {@link DatastoreV1.Read#withLiteralGqlQuery(String)}.
*
* <p>Write some test entities to datastore and then run a pipeline that
* reads and counts the total number of entities. Verify that the count matches
* the number of entities written.
*/
private void testE2EV1ReadWithGQLQuery(long limit) throws Exception {
String gqlQuery = String.format(
"SELECT * from %s WHERE __key__ HAS ANCESTOR KEY(%s, '%s')",
options.getKind(), options.getKind(), ancestor);
long expectedNumEntities = numEntities;
if (limit > 0) {
gqlQuery = String.format("%s LIMIT %d", gqlQuery, limit);
expectedNumEntities = limit;
}
DatastoreV1.Read read = DatastoreIO.v1().read()
.withProjectId(project)
.withLiteralGqlQuery(gqlQuery)
.withNamespace(options.getNamespace());
// Count the total number of entities
Pipeline p = Pipeline.create(options);
PCollection<Long> count = p
.apply(read)
.apply(Count.<Entity>globally());
PAssert.thatSingleton(count).isEqualTo(expectedNumEntities);
p.run();
}
开发者ID:apache,项目名称:beam,代码行数:33,代码来源:V1ReadIT.java
示例18: testSourcePrimitiveDisplayData
import com.google.datastore.v1.Entity; //导入依赖的package包/类
@Test
public void testSourcePrimitiveDisplayData() {
DisplayDataEvaluator evaluator = DisplayDataEvaluator.create();
int numSplits = 98;
PTransform<PBegin, PCollection<Entity>> read =
DatastoreIO.v1().read()
.withProjectId(PROJECT_ID)
.withQuery(Query.newBuilder().build())
.withNumQuerySplits(numSplits);
String assertMessage = "DatastoreIO read should include the '%s' in its primitive display data";
Set<DisplayData> displayData = evaluator.displayDataForPrimitiveSourceTransforms(read);
assertThat(String.format(assertMessage, "project id"),
displayData, hasItem(hasDisplayItem("projectId", PROJECT_ID)));
assertThat(String.format(assertMessage, "number of query splits"),
displayData, hasItem(hasDisplayItem("numQuerySplits", numSplits)));
}
开发者ID:apache,项目名称:beam,代码行数:18,代码来源:DatastoreV1Test.java
示例19: datastoreWriterFnTest
import com.google.datastore.v1.Entity; //导入依赖的package包/类
private void datastoreWriterFnTest(int numMutations) throws Exception {
// Create the requested number of mutations.
List<Mutation> mutations = new ArrayList<>(numMutations);
for (int i = 0; i < numMutations; ++i) {
mutations.add(
makeUpsert(Entity.newBuilder().setKey(makeKey("key" + i, i + 1)).build()).build());
}
DatastoreWriterFn datastoreWriter = new DatastoreWriterFn(StaticValueProvider.of(PROJECT_ID),
null, mockDatastoreFactory, new FakeWriteBatcher());
DoFnTester<Mutation, Void> doFnTester = DoFnTester.of(datastoreWriter);
doFnTester.setCloningBehavior(CloningBehavior.DO_NOT_CLONE);
doFnTester.processBundle(mutations);
int start = 0;
while (start < numMutations) {
int end = Math.min(numMutations, start + DATASTORE_BATCH_UPDATE_ENTITIES_START);
CommitRequest.Builder commitRequest = CommitRequest.newBuilder();
commitRequest.setMode(CommitRequest.Mode.NON_TRANSACTIONAL);
commitRequest.addAllMutations(mutations.subList(start, end));
// Verify all the batch requests were made with the expected mutations.
verify(mockDatastore, times(1)).commit(commitRequest.build());
start = end;
}
}
开发者ID:apache,项目名称:beam,代码行数:26,代码来源:DatastoreV1Test.java
示例20: testDatatoreWriterFnRetriesErrors
import com.google.datastore.v1.Entity; //导入依赖的package包/类
/** Tests {@link DatastoreWriterFn} with a failed request which is retried. */
@Test
public void testDatatoreWriterFnRetriesErrors() throws Exception {
List<Mutation> mutations = new ArrayList<>();
int numRpcs = 2;
for (int i = 0; i < DATASTORE_BATCH_UPDATE_ENTITIES_START * numRpcs; ++i) {
mutations.add(
makeUpsert(Entity.newBuilder().setKey(makeKey("key" + i, i + 1)).build()).build());
}
CommitResponse successfulCommit = CommitResponse.getDefaultInstance();
when(mockDatastore.commit(any(CommitRequest.class))).thenReturn(successfulCommit)
.thenThrow(
new DatastoreException("commit", Code.DEADLINE_EXCEEDED, "", null))
.thenReturn(successfulCommit);
DatastoreWriterFn datastoreWriter = new DatastoreWriterFn(StaticValueProvider.of(PROJECT_ID),
null, mockDatastoreFactory, new FakeWriteBatcher());
DoFnTester<Mutation, Void> doFnTester = DoFnTester.of(datastoreWriter);
doFnTester.setCloningBehavior(CloningBehavior.DO_NOT_CLONE);
doFnTester.processBundle(mutations);
}
开发者ID:apache,项目名称:beam,代码行数:23,代码来源:DatastoreV1Test.java
注:本文中的com.google.datastore.v1.Entity类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论