Skip to content

Commit fe5abc0

Browse files
author
Praful Makani
authored
docs(samples): fix checkstyle errors (#682)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [X] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/java-bigquery/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [X] Ensure the tests and linter pass - [X] Code coverage does not decrease (if any source code was changed) - [X] Appropriate docs were updated (if necessary) Fixes #681
1 parent 5acb756 commit fe5abc0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+347
-365
lines changed

samples/snippets/src/main/java/com/example/bigquery/AuthorizedViewTutorial.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ public static void authorizedViewTutorial(
5757
// [START bigquery_authorized_view_tutorial]
5858
// [START bigquery_avt_create_source_dataset]
5959
// Create a source dataset to store your table.
60-
Dataset sourceDataset = bigquery.create(DatasetInfo.of(sourceDatasetId));
60+
final Dataset sourceDataset = bigquery.create(DatasetInfo.of(sourceDatasetId));
6161
// [END bigquery_avt_create_source_dataset]
62-
6362
// [START bigquery_avt_create_source_table]
6463
// Populate a source table
6564
String tableQuery =
@@ -72,32 +71,27 @@ public static void authorizedViewTutorial(
7271
.build();
7372
bigquery.query(queryConfig);
7473
// [END bigquery_avt_create_source_table]
75-
7674
// [START bigquery_avt_create_shared_dataset]
7775
// Create a separate dataset to store your view
7876
Dataset sharedDataset = bigquery.create(DatasetInfo.of(sharedDatasetId));
7977
// [END bigquery_avt_create_shared_dataset]
80-
8178
// [START bigquery_avt_create_view]
8279
// Create the view in the new dataset
8380
String viewQuery =
8481
String.format(
85-
"SELECT commit, author.name as author, committer.name as committer, repo_name FROM %s.%s.%s",
82+
"SELECT commit, author.name as author, "
83+
+ "committer.name as committer, repo_name FROM %s.%s.%s",
8684
projectId, sourceDatasetId, sourceTableId);
87-
8885
ViewDefinition viewDefinition = ViewDefinition.of(viewQuery);
89-
9086
Table view =
9187
bigquery.create(TableInfo.of(TableId.of(sharedDatasetId, sharedViewId), viewDefinition));
9288
// [END bigquery_avt_create_view]
93-
9489
// [START bigquery_avt_shared_dataset_access]
9590
// Assign access controls to the dataset containing the view
9691
List<Acl> viewAcl = new ArrayList<>(sharedDataset.getAcl());
9792
viewAcl.add(Acl.of(new Acl.Group("example-analyst-group@google.com"), Acl.Role.READER));
9893
sharedDataset.toBuilder().setAcl(viewAcl).build().update();
9994
// [END bigquery_avt_shared_dataset_access]
100-
10195
// [START bigquery_avt_source_dataset_access]
10296
// Authorize the view to access the source dataset
10397
List<Acl> srcAcl = new ArrayList<>(sourceDataset.getAcl());

samples/snippets/src/main/java/com/example/bigquery/CopyTableCMEK.java renamed to samples/snippets/src/main/java/com/example/bigquery/CopyTableCmek.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.google.cloud.bigquery.TableId;
2828

2929
// Sample to copy a cmek table
30-
public class CopyTableCMEK {
30+
public class CopyTableCmek {
3131

3232
public static void main(String[] args) {
3333
// TODO(developer): Replace these variables before running the sample.
@@ -38,11 +38,11 @@ public static void main(String[] args) {
3838
String kmsKeyName = "MY_KMS_KEY_NAME";
3939
EncryptionConfiguration encryption =
4040
EncryptionConfiguration.newBuilder().setKmsKeyName(kmsKeyName).build();
41-
copyTableCMEK(
41+
copyTableCmek(
4242
sourceDatasetName, sourceTableId, destinationDatasetName, destinationTableId, encryption);
4343
}
4444

45-
public static void copyTableCMEK(
45+
public static void copyTableCmek(
4646
String sourceDatasetName,
4747
String sourceTableId,
4848
String destinationDatasetName,

samples/snippets/src/main/java/com/example/bigquery/CreateModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static void main(String[] args) {
4343
+ "learn_rate=0.4, "
4444
+ "learn_rate_strategy='constant' "
4545
+ ") AS ( "
46-
+ "SELECT 'a' AS f1, 2.0 AS label "
46+
+ "SELECT 'a' AS f1, 2.0 AS label "
4747
+ "UNION ALL "
4848
+ "SELECT 'b' AS f1, 3.8 AS label "
4949
+ ")";

samples/snippets/src/main/java/com/example/bigquery/CreateRoutineDDL.java renamed to samples/snippets/src/main/java/com/example/bigquery/CreateRoutineDdl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import com.google.cloud.bigquery.QueryJobConfiguration;
2626

2727
// Sample to create a routine using DDL
28-
public class CreateRoutineDDL {
28+
public class CreateRoutineDdl {
2929

3030
public static void main(String[] args) {
3131
// TODO(developer): Replace these variables before running the sample.
@@ -41,11 +41,12 @@ public static void main(String[] args) {
4141
+ "."
4242
+ routineId
4343
+ "`"
44-
+ "( arr ARRAY<STRUCT<name STRING, val INT64>>) AS ( (SELECT SUM(IF(elem.name = \"foo\",elem.val,null)) FROM UNNEST(arr) AS elem))";
45-
createRoutineDDL(sql);
44+
+ "( arr ARRAY<STRUCT<name STRING, val INT64>>) AS "
45+
+ "( (SELECT SUM(IF(elem.name = \"foo\",elem.val,null)) FROM UNNEST(arr) AS elem))";
46+
createRoutineDdl(sql);
4647
}
4748

48-
public static void createRoutineDDL(String sql) {
49+
public static void createRoutineDdl(String sql) {
4950
try {
5051
// Initialize client that will be used to send requests. This client only needs to be created
5152
// once, and can be reused for multiple requests.

samples/snippets/src/main/java/com/example/bigquery/CreateTableCMEK.java renamed to samples/snippets/src/main/java/com/example/bigquery/CreateTableCmek.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import com.google.cloud.bigquery.TableInfo;
3131

3232
// Sample to create a cmek table
33-
public class CreateTableCMEK {
33+
public class CreateTableCmek {
3434

3535
public static void main(String[] args) {
3636
// TODO(developer): Replace these variables before running the sample.
@@ -44,10 +44,10 @@ public static void main(String[] args) {
4444
// i.e. projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{cryptoKey}
4545
EncryptionConfiguration encryption =
4646
EncryptionConfiguration.newBuilder().setKmsKeyName(kmsKeyName).build();
47-
createTableCMEK(datasetName, tableName, schema, encryption);
47+
createTableCmek(datasetName, tableName, schema, encryption);
4848
}
4949

50-
public static void createTableCMEK(
50+
public static void createTableCmek(
5151
String datasetName, String tableName, Schema schema, EncryptionConfiguration configuration) {
5252
try {
5353
// Initialize client that will be used to send requests. This client only needs to be created

samples/snippets/src/main/java/com/example/bigquery/DDLCreateView.java renamed to samples/snippets/src/main/java/com/example/bigquery/DdlCreateView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import com.google.cloud.bigquery.QueryJobConfiguration;
2626

2727
// Sample to create a view using DDL
28-
public class DDLCreateView {
28+
public class DdlCreateView {
2929

3030
public static void main(String[] args) {
3131
// TODO(developer): Replace these variables before running the sample.

samples/snippets/src/main/java/com/example/bigquery/GrantViewAccess.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,17 @@ public static void grantViewAccess(String srcDatasetId, String viewDatasetId, St
4747
Dataset srcDataset = bigquery.getDataset(DatasetId.of(srcDatasetId));
4848
Dataset viewDataset = bigquery.getDataset(DatasetId.of(viewDatasetId));
4949
Table view = viewDataset.get(viewId);
50-
5150
// First, we'll add a group to the ACL for the dataset containing the view. This will allow
5251
// users within that group to query the view, but they must have direct access to any tables
5352
// referenced by the view.
54-
List<Acl> viewAcl = new ArrayList<>();
55-
viewAcl.addAll(viewDataset.getAcl());
53+
List<Acl> viewAcl = new ArrayList<>(viewDataset.getAcl());
5654
viewAcl.add(Acl.of(new Acl.Group("example-analyst-group@google.com"), Acl.Role.READER));
5755
viewDataset.toBuilder().setAcl(viewAcl).build().update();
58-
5956
// Now, we'll authorize a specific view against a source dataset, delegating access
6057
// enforcement. Once this has been completed, members of the group previously added to the
6158
// view dataset's ACL no longer require access to the source dataset to successfully query the
6259
// view
63-
List<Acl> srcAcl = new ArrayList<>();
64-
srcAcl.addAll(srcDataset.getAcl());
60+
List<Acl> srcAcl = new ArrayList<>(srcDataset.getAcl());
6561
srcAcl.add(Acl.of(new Acl.View(view.getTableId())));
6662
srcDataset.toBuilder().setAcl(srcAcl).build().update();
6763
System.out.println("Grant view access successfully");

samples/snippets/src/main/java/com/example/bigquery/InsertingDataTypes.java

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -41,56 +41,56 @@ public static void main(String[] args) {
4141
// TODO(developer): Replace these variables before running the sample.
4242
String datasetName = "MY_DATASET_NAME";
4343
String tableName = "MY_TABLE_NAME";
44-
45-
// Inserting data types
46-
Field name = Field.of("name", StandardSQLTypeName.STRING);
47-
Field age = Field.of("age", StandardSQLTypeName.INT64);
48-
Field school =
49-
Field.newBuilder("school", StandardSQLTypeName.BYTES).setMode(Field.Mode.REPEATED).build();
50-
Field location = Field.of("location", StandardSQLTypeName.GEOGRAPHY);
51-
Field measurements =
52-
Field.newBuilder("measurements", StandardSQLTypeName.FLOAT64)
53-
.setMode(Field.Mode.REPEATED)
54-
.build();
55-
Field day = Field.of("day", StandardSQLTypeName.DATE);
56-
Field firstTime = Field.of("firstTime", StandardSQLTypeName.DATETIME);
57-
Field secondTime = Field.of("secondTime", StandardSQLTypeName.TIME);
58-
Field thirdTime = Field.of("thirdTime", StandardSQLTypeName.TIMESTAMP);
59-
Field datesTime =
60-
Field.of("datesTime", StandardSQLTypeName.STRUCT, day, firstTime, secondTime, thirdTime);
61-
Schema schema = Schema.of(name, age, school, location, measurements, datesTime);
62-
63-
// Inserting Sample data
64-
Map<String, Object> datesTimeContent = new HashMap<>();
65-
datesTimeContent.put("day", "2019-1-12");
66-
datesTimeContent.put("firstTime", "2019-02-17 11:24:00.000");
67-
datesTimeContent.put("secondTime", "14:00:00");
68-
datesTimeContent.put("thirdTime", "2020-04-27T18:07:25.356Z");
69-
70-
Map<String, Object> rowContent = new HashMap<>();
71-
rowContent.put("name", "Tom");
72-
rowContent.put("age", 30);
73-
rowContent.put("school", "Test University".getBytes());
74-
rowContent.put("location", "POINT(1 2)");
75-
rowContent.put("measurements", new Float[] {50.05f, 100.5f});
76-
rowContent.put("datesTime", datesTimeContent);
77-
78-
insertingDataTypes(datasetName, tableName, schema, rowContent);
44+
insertingDataTypes(datasetName, tableName);
7945
}
8046

81-
public static void insertingDataTypes(
82-
String datasetName, String tableName, Schema schema, Map<String, Object> rowContent) {
47+
public static void insertingDataTypes(String datasetName, String tableName) {
8348
try {
8449
// Initialize client that will be used to send requests. This client only needs to be created
8550
// once, and can be reused for multiple requests.
8651
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
8752

53+
// Inserting data types
54+
Field name = Field.of("name", StandardSQLTypeName.STRING);
55+
Field age = Field.of("age", StandardSQLTypeName.INT64);
56+
Field school =
57+
Field.newBuilder("school", StandardSQLTypeName.BYTES)
58+
.setMode(Field.Mode.REPEATED)
59+
.build();
60+
Field location = Field.of("location", StandardSQLTypeName.GEOGRAPHY);
61+
Field measurements =
62+
Field.newBuilder("measurements", StandardSQLTypeName.FLOAT64)
63+
.setMode(Field.Mode.REPEATED)
64+
.build();
65+
Field day = Field.of("day", StandardSQLTypeName.DATE);
66+
Field firstTime = Field.of("firstTime", StandardSQLTypeName.DATETIME);
67+
Field secondTime = Field.of("secondTime", StandardSQLTypeName.TIME);
68+
Field thirdTime = Field.of("thirdTime", StandardSQLTypeName.TIMESTAMP);
69+
Field datesTime =
70+
Field.of("datesTime", StandardSQLTypeName.STRUCT, day, firstTime, secondTime, thirdTime);
71+
Schema schema = Schema.of(name, age, school, location, measurements, datesTime);
72+
8873
TableId tableId = TableId.of(datasetName, tableName);
8974
TableDefinition tableDefinition = StandardTableDefinition.of(schema);
9075
TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build();
9176

9277
bigquery.create(tableInfo);
9378

79+
// Inserting Sample data
80+
Map<String, Object> datesTimeContent = new HashMap<>();
81+
datesTimeContent.put("day", "2019-1-12");
82+
datesTimeContent.put("firstTime", "2019-02-17 11:24:00.000");
83+
datesTimeContent.put("secondTime", "14:00:00");
84+
datesTimeContent.put("thirdTime", "2020-04-27T18:07:25.356Z");
85+
86+
Map<String, Object> rowContent = new HashMap<>();
87+
rowContent.put("name", "Tom");
88+
rowContent.put("age", 30);
89+
rowContent.put("school", "Test University".getBytes());
90+
rowContent.put("location", "POINT(1 2)");
91+
rowContent.put("measurements", new Float[] {50.05f, 100.5f});
92+
rowContent.put("datesTime", datesTimeContent);
93+
9494
InsertAllResponse response =
9595
bigquery.insertAll(InsertAllRequest.newBuilder(tableId).addRow(rowContent).build());
9696

samples/snippets/src/main/java/com/example/bigquery/LoadAvroFromGCS.java renamed to samples/snippets/src/main/java/com/example/bigquery/LoadAvroFromGcs.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@
2727
import com.google.cloud.bigquery.TableId;
2828

2929
// Sample to load Avro data from Cloud Storage into a new BigQuery table
30-
public class LoadAvroFromGCS {
30+
public class LoadAvroFromGcs {
3131

3232
public static void main(String[] args) {
3333
// TODO(developer): Replace these variables before running the sample.
3434
String datasetName = "MY_DATASET_NAME";
3535
String tableName = "MY_TABLE_NAME";
3636
String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.avro";
37-
loadAvroFromGCS(datasetName, tableName, sourceUri);
37+
loadAvroFromGcs(datasetName, tableName, sourceUri);
3838
}
3939

40-
public static void loadAvroFromGCS(String datasetName, String tableName, String sourceUri) {
40+
public static void loadAvroFromGcs(String datasetName, String tableName, String sourceUri) {
4141
try {
4242
// Initialize client that will be used to send requests. This client only needs to be created
4343
// once, and can be reused for multiple requests.

samples/snippets/src/main/java/com/example/bigquery/LoadAvroFromGCSTruncate.java renamed to samples/snippets/src/main/java/com/example/bigquery/LoadAvroFromGcsTruncate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@
2727
import com.google.cloud.bigquery.TableId;
2828

2929
// Sample to overwrite the BigQuery table data by loading a AVRO file from GCS
30-
public class LoadAvroFromGCSTruncate {
30+
public class LoadAvroFromGcsTruncate {
3131

3232
public static void main(String[] args) {
3333
// TODO(developer): Replace these variables before running the sample.
3434
String datasetName = "MY_DATASET_NAME";
3535
String tableName = "MY_TABLE_NAME";
3636
String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.avro";
37-
loadAvroFromGCSTruncate(datasetName, tableName, sourceUri);
37+
loadAvroFromGcsTruncate(datasetName, tableName, sourceUri);
3838
}
3939

40-
public static void loadAvroFromGCSTruncate(
40+
public static void loadAvroFromGcsTruncate(
4141
String datasetName, String tableName, String sourceUri) {
4242
try {
4343
// Initialize client that will be used to send requests. This client only needs to be created

0 commit comments

Comments
 (0)