当前位置: 首页>>代码示例>>Java>>正文


Java Entity类代码示例

本文整理汇总了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;
  }
 
开发者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


注:本文中的com.google.datastore.v1.Entity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。