本文整理汇总了Java中com.google.api.services.bigquery.model.TableSchema.setFields方法的典型用法代码示例。如果您正苦于以下问题:Java TableSchema.setFields方法的具体用法?Java TableSchema.setFields怎么用?Java TableSchema.setFields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.services.bigquery.model.TableSchema
的用法示例。
在下文中一共展示了TableSchema.setFields方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exampleTable
import com.google.api.services.bigquery.model.TableSchema; //导入方法依赖的package包/类
private TableSchema exampleTable() {
TableSchema personTable = new TableSchema();
personTable.setFields(Arrays.asList(
new TableFieldSchema().setName("__key__").setType("STRING"),
new TableFieldSchema().setName("firstName").setType("STRING"),
new TableFieldSchema().setName("age").setType("INTEGER"),
new TableFieldSchema().setName("pic").setType("BYTES"),
new TableFieldSchema().setName("weight").setType("FLOAT"),
new TableFieldSchema().setName("isGoogler").setType("BOOLEAN"),
new TableFieldSchema().setName("birthTimestamp").setType("TIMESTAMP"),
new TableFieldSchema().setName("birthDate").setType("DATE"),
new TableFieldSchema().setName("birthTime").setType("TIME"),
new TableFieldSchema().setName("birthDateTime").setType("DATETIME"),
new TableFieldSchema().setName("favFruits").setType("STRING").setMode("REPEATED"),
new TableFieldSchema().setName("body").setType("RECORD").setFields(Arrays.asList(
new TableFieldSchema().setName("height").setType("FLOAT"),
new TableFieldSchema().setName("ethnicity").setType("STRING")
)),
new TableFieldSchema().setName("vacations").setType("RECORD").setMode("REPEATED")
.setFields(Arrays.asList(
new TableFieldSchema().setName("place").setType("STRING"),
new TableFieldSchema().setName("time").setType("TIMESTAMP")
))
));
return personTable;
}
示例2: loadSchema
import com.google.api.services.bigquery.model.TableSchema; //导入方法依赖的package包/类
public static TableSchema loadSchema(Reader schemaSource){
TableSchema sourceSchema = new TableSchema();
List<TableFieldSchema> fields = (new Gson()).<List<TableFieldSchema>>fromJson(
schemaSource,
(new ArrayList<TableFieldSchema>()).getClass());
sourceSchema.setFields(fields);
return sourceSchema;
}
示例3: getExpectedJob
import com.google.api.services.bigquery.model.TableSchema; //导入方法依赖的package包/类
/**
* Helper method to get the load request to BigQuery with numValues copies of jsonValue.
*/
private Job getExpectedJob() {
// Configure a write job.
JobConfigurationLoad loadConfig = new JobConfigurationLoad();
loadConfig.setCreateDisposition("CREATE_IF_NEEDED");
loadConfig.setWriteDisposition("WRITE_TRUNCATE");
loadConfig.setSourceFormat("NEWLINE_DELIMITED_JSON");
// Describe the resulting table you are importing to:
loadConfig.setDestinationTable(getSampleTableRef());
// Create and set the output schema.
TableSchema schema = new TableSchema();
schema.setFields(fields);
loadConfig.setSchema(schema);
// Create Job configuration.
JobConfiguration jobConfig = new JobConfiguration();
jobConfig.setLoad(loadConfig);
// Set the output write job.
Job expectedJob = new Job();
expectedJob.setConfiguration(jobConfig);
expectedJob.setJobReference(jobReference);
return expectedJob;
}
示例4: createTable
import com.google.api.services.bigquery.model.TableSchema; //导入方法依赖的package包/类
public void createTable(String datasetName, String tableName, List<TableFieldSchema> schemaFields) throws GeneralSecurityException, IOException {
Bigquery bigquery = GoogleServices.getBigqueryServiceDomainWide();
TableSchema schema = new TableSchema();
schema.setFields(schemaFields);
Table table = new Table();
table.setSchema(schema);
TableReference tableRef = new TableReference();
tableRef.setDatasetId(datasetName);
tableRef.setProjectId(AppHelper.getAppId());
tableRef.setTableId(tableName);
table.setTableReference(tableRef);
try {
bigquery.tables().insert(AppHelper.getAppId(), datasetName, table).execute();
} catch (GoogleJsonResponseException ex) {
if (ex.getStatusCode() != 409) throw ex;
}
}
示例5: loadSchema
import com.google.api.services.bigquery.model.TableSchema; //导入方法依赖的package包/类
private void loadSchema(String fileUri, TableSchema schema) throws IOException {
// TODO(frew): Move to AnalysisUtility
String schemaFileUri = fileUri + ".schema";
String schemaFileName = "/gs/" + schemaFileUri.substring(schemaFileUri.indexOf("//") + 2);
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
BlobKey key = blobstoreService.createGsBlobKey(schemaFileName);
System.out.println("Schema File Name : " + schemaFileName);
String schemaLine = AnalysisUtility.loadSchemaStr(schemaFileName);
String[] schemaFieldStrs = schemaLine.split(",");
List<TableFieldSchema> schemaFields = new ArrayList<TableFieldSchema>(schemaFieldStrs.length);
for (String schemaFieldStr : schemaFieldStrs) {
TableFieldSchema field = new TableFieldSchema();
String[] schemaFieldStrParts = schemaFieldStr.split(":");
field.setName(schemaFieldStrParts[0]);
field.setType(schemaFieldStrParts[1]);
field.setMode("NULLABLE");
schemaFields.add(field);
}
schema.setFields(schemaFields);
}
示例6: getBigQuerySchema
import com.google.api.services.bigquery.model.TableSchema; //导入方法依赖的package包/类
/**
* Starting from the list of columns this method returns a {@link TableSchema} definition for BigQuery.
*
* @param tableColumns a list of columns specification
* @returna {@link TableSchema} with the definition of a BigQuery table
* @throws SQLException if something goes wrong with SQL Server data types recognition
*/
public static TableSchema getBigQuerySchema(List<MsSqlColumn> tableColumns) throws SQLException{
if (tableColumns == null)
return null;
TableSchema schema = new TableSchema();
List<TableFieldSchema> fieldSchemas = new ArrayList<TableFieldSchema>();
for (MsSqlColumn column : tableColumns) {
TableFieldSchema fieldSchema = new TableFieldSchema();
fieldSchema.setName(column.getName());
String dataTypeString = column.getDataType().toUpperCase();
MsSqlDataType dataType;
try {
dataType = MsSqlDataType.valueOf(dataTypeString);
} catch (Exception e) {
_log.error(String.format("Unrecognized data type %s", dataTypeString));
throw new SQLException(String.format("Unrecognized data type %s", dataTypeString));
}
if (PipelineStructures.msSqlToBqTypeMap.containsKey(dataType)){
fieldSchema.setType(PipelineStructures.msSqlToBqTypeMap.get(dataType));
} else {
_log.error(String.format("DataType %s not supported!", dataType));
throw new SQLException(String.format("DataType %s not supported!", dataType));
}
fieldSchemas.add(fieldSchema);
}
schema.setFields(fieldSchemas);
return schema;
}
示例7: schema
import com.google.api.services.bigquery.model.TableSchema; //导入方法依赖的package包/类
/**
* Returns a TableSchema for this list of fields.
* @return the BigQuery TableSchema object for this list of fields
*/
public TableSchema schema() {
TableSchema result = new TableSchema();
result.setFields(schemaFields);
return result;
}
开发者ID:GoogleCloudPlatform,项目名称:bigquery-etl-dataflow-sample,代码行数:10,代码来源:FieldSchemaListBuilder.java
示例8: testConvertBigQuerySchemaToAvroSchema
import com.google.api.services.bigquery.model.TableSchema; //导入方法依赖的package包/类
@Test
public void testConvertBigQuerySchemaToAvroSchema() {
TableSchema tableSchema = new TableSchema();
tableSchema.setFields(fields);
Schema avroSchema =
BigQueryAvroUtils.toGenericAvroSchema("testSchema", tableSchema.getFields());
assertThat(avroSchema.getField("number").schema(), equalTo(Schema.create(Type.LONG)));
assertThat(
avroSchema.getField("species").schema(),
equalTo(Schema.createUnion(Schema.create(Type.NULL), Schema.create(Type.STRING))));
assertThat(
avroSchema.getField("quality").schema(),
equalTo(Schema.createUnion(Schema.create(Type.NULL), Schema.create(Type.DOUBLE))));
assertThat(
avroSchema.getField("quantity").schema(),
equalTo(Schema.createUnion(Schema.create(Type.NULL), Schema.create(Type.LONG))));
assertThat(
avroSchema.getField("birthday").schema(),
equalTo(Schema.createUnion(Schema.create(Type.NULL), Schema.create(Type.LONG))));
assertThat(
avroSchema.getField("flighted").schema(),
equalTo(Schema.createUnion(Schema.create(Type.NULL), Schema.create(Type.BOOLEAN))));
assertThat(
avroSchema.getField("sound").schema(),
equalTo(Schema.createUnion(Schema.create(Type.NULL), Schema.create(Type.BYTES))));
assertThat(
avroSchema.getField("anniversaryDate").schema(),
equalTo(Schema.createUnion(Schema.create(Type.NULL), Schema.create(Type.STRING))));
assertThat(
avroSchema.getField("anniversaryDatetime").schema(),
equalTo(Schema.createUnion(Schema.create(Type.NULL), Schema.create(Type.STRING))));
assertThat(
avroSchema.getField("anniversaryTime").schema(),
equalTo(Schema.createUnion(Schema.create(Type.NULL), Schema.create(Type.STRING))));
assertThat(
avroSchema.getField("scion").schema(),
equalTo(
Schema.createUnion(
Schema.create(Type.NULL),
Schema.createRecord(
"scion",
"org.apache.beam.sdk.io.gcp.bigquery",
"Translated Avro Schema for scion",
false,
ImmutableList.of(
new Field(
"species",
Schema.createUnion(
Schema.create(Type.NULL), Schema.create(Type.STRING)),
null,
(Object) null))))));
assertThat(
avroSchema.getField("associates").schema(),
equalTo(
Schema.createArray(
Schema.createRecord(
"associates",
"org.apache.beam.sdk.io.gcp.bigquery",
"Translated Avro Schema for associates",
false,
ImmutableList.of(
new Field(
"species",
Schema.createUnion(
Schema.create(Type.NULL), Schema.create(Type.STRING)),
null,
(Object) null))))));
}