Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.flink.bigquery.examples;
import org.apache.flink.api.connector.source.Boundedness;
import org.apache.flink.api.java.utils.ParameterTool;
import org.apache.flink.connector.base.DeliveryGuarantee;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.annotation.DataTypeHint;
import org.apache.flink.table.annotation.FunctionHint;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.table.functions.TableFunction;
import org.apache.flink.types.Row;
import com.google.cloud.flink.bigquery.sink.serializer.BigQueryTableSchemaProvider;
import com.google.cloud.flink.bigquery.table.config.BigQueryReadTableConfig;
import com.google.cloud.flink.bigquery.table.config.BigQuerySinkTableConfig;
import com.google.cloud.flink.bigquery.table.config.BigQueryTableConfig;
import org.apache.avro.generic.GenericRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.flink.table.api.Expressions.$;
import static org.apache.flink.table.api.Expressions.call;
/**
* A simple BigQuery table read and sink example with Flink's Table API.
*
*
The Flink pipeline will try to read the specified BigQuery table according to the command line
* arguments, returning {@link GenericRecord} representing the rows, and print the result of
* specified operations or write to a BigQuery table via sink.
*
*
*
Specify the BQ dataset and table with an optional row restriction. Users can configure a
* source mode, i.e bounded or unbounded. Bounded implies that the BQ table will be read once
* at the time of execution, analogous to a batch job. Unbounded source implies that the BQ
* table will be periodically polled for new data. Resulting records can be written to another
* BQ table, with allowed delivery (write) guarantees at-least-once or exactly-once.
* The sequence of operations in both pipelines is: source > flatMap > sink
* Flink command line format is:
* flink run {additional runtime params} {path to this jar}/BigQueryTableExample.jar
*
* --gcp-source-project {required; project ID containing the source table}
* --bq-source-dataset {required; name of dataset containing the source table}
* --bq-source-table {required; name of table to read}
* --gcp-sink-project {required; project ID containing the sink table}
* --bq-sink-dataset {required; name of dataset containing the sink table}
* --bq-sink-table {required; name of table to write to}
* --mode {optional; source read type. Allowed values are bounded (default) or unbounded or
* hybrid}
* --restriction {optional; SQL filter applied at the BigQuery table before reading}
* --limit {optional; maximum records to read from BigQuery table}
* --checkpoint-interval {optional; milliseconds between state checkpoints}
* --partition-discovery-interval {optional; minutes between polling table for new data. Used
* in unbounded/hybrid mode}
* --delivery-guarantee {optional; sink consistency. Allowed values are at-least-once
* (default) or exactly-once}
*
*/
public class BigQueryTableExample {
private static final Logger LOG = LoggerFactory.getLogger(BigQueryTableExample.class);
public static void main(String[] args) throws Exception {
// parse input arguments
final ParameterTool parameterTool = ParameterTool.fromArgs(args);
if (parameterTool.getNumberOfParameters() < 1) {
LOG.error(
"Missing parameters!\n"
+ "Usage: flink run "
+ " --gcp-source-project "
+ " --bq-source-dataset "
+ " --bq-source-table