Skip to content

test: do not merge #3664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 41 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
fb370bb
test: do not merge
PhongChuong Feb 3, 2025
9b81692
test: do not merge
PhongChuong Feb 3, 2025
b5a30ee
test: do not merge
PhongChuong Feb 3, 2025
5bcf0bb
test: do not merge
PhongChuong Feb 3, 2025
fff173d
test: do not merge
PhongChuong Feb 3, 2025
01da459
test: do not merge
PhongChuong Feb 3, 2025
2643f4d
test: do not merge
PhongChuong Feb 5, 2025
25235a3
test: do not merge
PhongChuong Feb 5, 2025
03ef85a
test: do not merge
PhongChuong Feb 5, 2025
507e3b4
test: do not merge
PhongChuong Feb 5, 2025
555ce30
test: do not merge
PhongChuong Feb 6, 2025
d4e808f
cast to HttpBigQueryRpc
PhongChuong Feb 14, 2025
3b6ec82
cast to HttpBigQueryRpc
PhongChuong Feb 14, 2025
89f8aaa
cast to HttpBigQueryRpc
PhongChuong Feb 14, 2025
b64afdc
cast to HttpBigQueryRpc
PhongChuong Feb 14, 2025
6121c10
cast to HttpBigQueryRpc
PhongChuong Feb 14, 2025
92fc010
cast to HttpBigQueryRpc
PhongChuong Feb 14, 2025
16ebb5c
cast to HttpBigQueryRpc
PhongChuong Feb 14, 2025
830ae08
cast to HttpBigQueryRpc
PhongChuong Feb 14, 2025
183280b
cast to HttpBigQueryRpc
PhongChuong Feb 14, 2025
4c834aa
cast to HttpBigQueryRpc
PhongChuong Feb 14, 2025
10bf47b
cast to HttpBigQueryRpc
PhongChuong Feb 14, 2025
8903a91
testing
PhongChuong Feb 18, 2025
b3653a1
testing
PhongChuong Feb 18, 2025
2d12ffb
testing
PhongChuong Feb 18, 2025
a8f3ca9
testing
PhongChuong Feb 18, 2025
62dbffe
testing
PhongChuong Feb 18, 2025
2e952e4
testing
PhongChuong Feb 18, 2025
3081181
testing
PhongChuong Feb 18, 2025
7255776
testing
PhongChuong Feb 18, 2025
d9d9abb
testing
PhongChuong Feb 18, 2025
b165a58
testing
PhongChuong Feb 18, 2025
a3793f7
testing
PhongChuong Feb 18, 2025
8447a3e
testing
PhongChuong Feb 18, 2025
e32d99f
testing
PhongChuong Feb 18, 2025
fcaf591
testing
PhongChuong Feb 18, 2025
f155d63
testing
PhongChuong Feb 18, 2025
6cb0494
testing
PhongChuong Feb 18, 2025
b3b2437
testing
PhongChuong Feb 18, 2025
0509104
testing
PhongChuong Feb 18, 2025
40c1030
testing
PhongChuong Feb 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class BigQueryOptions extends ServiceOptions<BigQuery, BigQueryOptions> {
private static final String API_SHORT_NAME = "BigQuery";
private static final int DEFAULT_READ_API_TIME_OUT = 60000;
private static final String BIGQUERY_SCOPE = "https://www.googleapis.com/auth/bigquery";
// TODO(NOW)
private static final Set<String> SCOPES = ImmutableSet.of(BIGQUERY_SCOPE);
private static final long serialVersionUID = -2437598817433266048L;
private final String location;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,29 @@ public static void setAuthDriveScope() throws IOException {
"https://www.googleapis.com/auth/bigquery",
"https://www.googleapis.com/auth/drive"));

// TODO(NOW)
// if (ServiceAccountCredentials.getApplicationDefault().equals(credentials)) {
// System.out.println("CHUONGPH: equal error: \n");
// throw new IOException();
// } else {
// System.out.println("CHUONGPH: not equal error: \n");
// throw new IOException();
// }

try {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests.
BigQuery bigquery =
BigQueryOptions.newBuilder().setCredentials(credentials).build().getService();

// System.out.println("CHUONGPH: Scopes \n" + BigQueryOptions.newBuilder().setCredentials(credentials).build().getScopes());

// Use the client.
System.out.println("Auth succeeded with multiple scopes. Datasets:");
for (Dataset dataset : bigquery.listDatasets().iterateAll()) {
System.out.printf("Dataset: %s%n", dataset.getDatasetId().getDataset());
}
// throw new IOException();
} catch (BigQueryException e) {
System.out.println("Auth failed due to error: \n" + e.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.example.bigquery;

// [START bigquery_create_table]
import com.google.auth.oauth2.GoogleCredentials;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQueryException;
import com.google.cloud.bigquery.BigQueryOptions;
Expand All @@ -27,6 +29,10 @@
import com.google.cloud.bigquery.TableDefinition;
import com.google.cloud.bigquery.TableId;
import com.google.cloud.bigquery.TableInfo;
import com.google.cloud.bigquery.QueryJobConfiguration;
import com.google.cloud.bigquery.TableResult;
import com.google.common.collect.ImmutableSet;
import java.io.IOException;

public class CreateTable {

Expand All @@ -43,17 +49,50 @@ public static void main(String[] args) {

public static void createTable(String datasetName, String tableName, Schema schema) {
try {
// Create credentials with Drive & BigQuery API scopes.
// Both APIs must be enabled for your project before running this code.
GoogleCredentials credentials =
ServiceAccountCredentials.getApplicationDefault()
.createScoped(
ImmutableSet.of(
"https://www.googleapis.com/auth/bigquery",
"https://www.googleapis.com/auth/drive"));

// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests.
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
BigQuery bigquery =
BigQueryOptions.newBuilder().setCredentials(credentials).build().getService();
// // Initialize client that will be used to send requests. This client only needs to be created
// // once, and can be reused for multiple requests.
// BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();

TableId tableId = TableId.of(datasetName, tableName);
TableDefinition tableDefinition = StandardTableDefinition.of(schema);
TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build();

bigquery.create(tableInfo);
System.out.println("Table created successfully");
} catch (BigQueryException e) {

// TODO(NOW)
// String query = String.format("SELECT * FROM %s.INFORMATION_SCHEMA.SESSIONS_BY_USER", datasetName);
String query = "SELECT * FROM region-us.INFORMATION_SCHEMA.SESSIONS_BY_USER";
// Create the query job.
QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query).build();

// Execute the query.
TableResult result = bigquery.query(queryConfig);

// Print the results.
result
.iterateAll()
.forEach(
row -> {
System.out.print("creation_time:" + row.get("creation_time").getStringValue());
System.out.print(", project_id:" + row.get("project_id").getStringValue());
System.out.print(", session_id:" + row.get("session_id").getStringValue());
System.out.print(", user_email:" + row.get("user_email").getStringValue());
System.out.println();
});
} catch (BigQueryException | InterruptedException | IOException e) {
System.out.println("Table was not created. \n" + e.toString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
// Sample to queries an external data source using a permanent table
public class QueryExternalSheetsPerm {

public static void main(String[] args) {
public static void main(String[] args) throws BigQueryException, InterruptedException, IOException {
// TODO(developer): Replace these variables before running the sample.
String datasetName = "MY_DATASET_NAME";
String tableName = "MY_TABLE_NAME";
Expand All @@ -53,8 +53,8 @@ public static void main(String[] args) {
}

public static void queryExternalSheetsPerm(
String datasetName, String tableName, String sourceUri, Schema schema, String query) {
try {
String datasetName, String tableName, String sourceUri, Schema schema, String query) throws BigQueryException, InterruptedException, IOException {
// try {

// Create credentials with Drive & BigQuery API scopes.
// Both APIs must be enabled for your project before running this code.
Expand Down Expand Up @@ -91,9 +91,9 @@ public static void queryExternalSheetsPerm(
.forEach(row -> row.forEach(val -> System.out.printf("%s,", val.toString())));

System.out.println("Query on external permanent table performed successfully.");
} catch (BigQueryException | InterruptedException | IOException e) {
System.out.println("Query not performed \n" + e.toString());
}
// } catch (BigQueryException | InterruptedException | IOException e) {
// System.out.println("Query not performed \n" + e.toString());
// // }
}
}
// [END bigquery_query_external_sheets_perm]

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.Ignore;

@Ignore
public class AuthDriveScopeIT {

private final Logger log = Logger.getLogger(this.getClass().getName());
Expand Down Expand Up @@ -55,4 +57,4 @@ public void setAuthDriveScope() throws IOException {
AuthDriveScope.setAuthDriveScope();
assertThat(bout.toString()).contains("Auth succeeded with multiple scopes.");
}
}
}
Loading
Loading