The BigQuery sample application demonstrates some common operations with Google Cloud BigQuery and is compatible with Native Image compilation.
You will need to follow these prerequisite steps in order to run the samples:
-
If you have not already, create a Google Cloud Platform Project.
-
Install the Google Cloud SDK which will allow you to run the sample with your project's credentials.
Once installed, log in with Application Default Credentials using the following command:
gcloud auth application-default login
Note: Authenticating with Application Default Credentials is convenient to use during development, but we recommend alternate methods of authentication during production use.
-
Install the native image compiler.
You can follow the installation instructions from the GraalVM website. After following the instructions, ensure that you install the native image extension installed by running:
gu install native-image
Once you finish following the instructions, verify that the default version of Java is set to the GraalVM version by running
java -version
in a terminal.You will see something similar to the below output:
$ java -version openjdk version "11.0.7" 2020-04-14 OpenJDK Runtime Environment GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02) OpenJDK 64-Bit Server VM GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02, mixed mode, sharing)
Navigate to this directory in a new terminal.
-
Compile the application using the Native Image Compiler. This step may take a few minutes.
mvn package -P native -DskipTests
-
Run the application:
./target/native-image-sample
-
The application will create a sample BigQuery dataset in your GCP project called
nativeimage_test_dataset
and perform some simple operations like creating a table, inserting data, and running a query.If you would like to delete the BigQuery dataset later, you can manage your BigQuery resources through Google Cloud Console to clean up BigQuery resources under your project.
When you run the application, you'll see output like this in the terminal:
Created new table: nativeimage_test_table_2351b0891d2f48af9309bd289c3bad13 Successfully inserted test row. Queried the following records: User id: TestUser-2f39e3ec-d81a-483f-9ec0-b9bd54155710 | age: 40 Deleted table: nativeimage_test_table_2351b0891d2f48af9309bd289c3bad13
In order to run the sample integration test, call the following command:
mvn test -Pnative