use of org.apache.beam.sdk.extensions.sql.example.model.Customer in project beam by apache.
the class BeamSqlPojoExample method main.
public static void main(String[] args) {
PipelineOptions options = PipelineOptionsFactory.fromArgs(args).create();
Pipeline pipeline = Pipeline.create(options);
// First step is to get PCollections of source objects.
// In this example we create them directly in memory using Create.of().
//
// In real world such PCollections will likely be obtained from some other source,
// e.g. a database or a text file. This process is not specific to Beam SQL,
// please consult Beam programming guide for details.
PCollection<Customer> customers = loadCustomers(pipeline);
PCollection<Order> orders = loadOrders(pipeline);
// Example 1. Run a simple query over java objects:
PCollection<Row> customersFromWonderland = customers.apply(SqlTransform.query("SELECT id, name " + " FROM PCOLLECTION " + " WHERE countryOfResidence = 'Wonderland'"));
// Output the results of the query:
customersFromWonderland.apply(logRecords(": is from Wonderland"));
// Example 2. Query the results of the first query:
PCollection<Row> totalInWonderland = customersFromWonderland.apply(SqlTransform.query("SELECT COUNT(id) FROM PCOLLECTION"));
// Output the results of the query:
totalInWonderland.apply(logRecords(": total customers in Wonderland"));
// Example 3. Query multiple PCollections of Java objects:
PCollection<Row> ordersByGrault = PCollectionTuple.of(new TupleTag<>("customers"), customers).and(new TupleTag<>("orders"), orders).apply(SqlTransform.query("SELECT customers.name, ('order id:' || CAST(orders.id AS VARCHAR))" + " FROM orders " + " JOIN customers ON orders.customerId = customers.id" + " WHERE customers.name = 'Grault'"));
// Output the results of the query:
ordersByGrault.apply(logRecords(": ordered by 'Grault'"));
pipeline.run().waitUntilFinish();
}
Aggregations