Search in sources :

Example 1 with BigQueryDatasetProperties

use of org.talend.components.bigquery.BigQueryDatasetProperties in project components by Talend.

the class BigQueryDatasetTestIT method createDatasetProperties.

/**
 * @return the properties for this dataset, fully initialized with the default values and the datastore credentials
 * from the System environment.
 */
public static BigQueryDatasetProperties createDatasetProperties() {
    // Configure the dataset.
    BigQueryDatastoreProperties datastoreProps = new BigQueryDatastoreProperties(null);
    datastoreProps.init();
    datastoreProps.projectName.setValue(System.getProperty("bigquery.project"));
    datastoreProps.serviceAccountFile.setValue(System.getProperty("bigquery.service.account.file"));
    datastoreProps.tempGsFolder.setValue(System.getProperty("bigquery.gcp.temp.folder"));
    BigQueryDatasetProperties datasetProps = new BigQueryDatasetProperties(null);
    datasetProps.init();
    datasetProps.setDatastoreProperties(datastoreProps);
    return datasetProps;
}
Also used : BigQueryDatastoreProperties(org.talend.components.bigquery.BigQueryDatastoreProperties) BigQueryDatasetProperties(org.talend.components.bigquery.BigQueryDatasetProperties)

Example 2 with BigQueryDatasetProperties

use of org.talend.components.bigquery.BigQueryDatasetProperties in project components by Talend.

the class BigQueryTestConstants method createDatasetFromTable.

public static BigQueryDatasetProperties createDatasetFromTable(BigQueryDatastoreProperties datastore, String datasetName, String tableName) {
    BigQueryDatasetProperties dataset = new BigQueryDatasetProperties("dataset");
    dataset.init();
    dataset.setDatastoreProperties(datastore);
    dataset.bqDataset.setValue(datasetName);
    dataset.sourceType.setValue(BigQueryDatasetProperties.SourceType.TABLE_NAME);
    dataset.tableName.setValue(tableName);
    return dataset;
}
Also used : BigQueryDatasetProperties(org.talend.components.bigquery.BigQueryDatasetProperties)

Example 3 with BigQueryDatasetProperties

use of org.talend.components.bigquery.BigQueryDatasetProperties in project components by Talend.

the class BigQueryTestConstants method createDatasetFromQuery.

public static BigQueryDatasetProperties createDatasetFromQuery(BigQueryDatastoreProperties datastore, String query, boolean useLegacy) {
    BigQueryDatasetProperties dataset = new BigQueryDatasetProperties("dataset");
    dataset.init();
    dataset.setDatastoreProperties(datastore);
    dataset.sourceType.setValue(BigQueryDatasetProperties.SourceType.QUERY);
    dataset.query.setValue(query);
    dataset.useLegacySql.setValue(useLegacy);
    return dataset;
}
Also used : BigQueryDatasetProperties(org.talend.components.bigquery.BigQueryDatasetProperties)

Example 4 with BigQueryDatasetProperties

use of org.talend.components.bigquery.BigQueryDatasetProperties in project components by Talend.

the class BigQueryDatasetTestIT method testBasic.

@Test
public void testBasic() throws Exception {
    BigQueryDatasetProperties props = createDatasetProperties();
    props.sourceType.setValue(SourceType.QUERY);
    props.query.setValue("SELECT * FROM [bigquery-public-data:samples.shakespeare] LIMIT 1");
    props.useLegacySql.setValue(true);
    final List<IndexedRecord> consumed = new ArrayList<>();
    RuntimeInfo ri = def.getRuntimeInfo(props);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(ri, getClass().getClassLoader())) {
        DatasetRuntime runtime = (DatasetRuntime) si.getInstance();
        runtime.initialize(null, props);
        assertThat(runtime, not(nullValue()));
        Schema s = runtime.getSchema();
        assertThat(s, not(nullValue()));
        runtime.getSample(100, new Consumer<IndexedRecord>() {

            @Override
            public void accept(IndexedRecord ir) {
                consumed.add(ir);
            }
        });
    }
    assertThat(consumed, hasSize(1));
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) IndexedRecord(org.apache.avro.generic.IndexedRecord) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) DatasetRuntime(org.talend.components.common.dataset.runtime.DatasetRuntime) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) BigQueryDatasetProperties(org.talend.components.bigquery.BigQueryDatasetProperties) Test(org.junit.Test)

Aggregations

BigQueryDatasetProperties (org.talend.components.bigquery.BigQueryDatasetProperties)4 ArrayList (java.util.ArrayList)1 Schema (org.apache.avro.Schema)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 Test (org.junit.Test)1 BigQueryDatastoreProperties (org.talend.components.bigquery.BigQueryDatastoreProperties)1 DatasetRuntime (org.talend.components.common.dataset.runtime.DatasetRuntime)1 RuntimeInfo (org.talend.daikon.runtime.RuntimeInfo)1 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)1