java


Unable to Connect to BigQuery from local App Engine instance in Eclipse


I'm new to Google App Engine and I'm trying to run through some of the tutorials to see how this would work for my organization. We are looking at putting some of our data into BigQuery and converting some of our Web applications to App Engine which would need to access BigQuery data.
I am using the java-docs-samples-master code, specifically bigquery/cloud-client/src/main/java/com/example/bigquery/SimpleApp.java
I can run this from the command line using
mvn exec:java -Dexec.mainClass=com.example.bigquery.SimpleAppMain
I incorporate the code into App Engine, which I'm running in Eclipse and created a wrapper so I could still run it from the command line. It works when running from the command line but I get an error when I run it from App Engine in Eclipse.
Is there something I'm missing to configure my local App Engine to connect to Big Query?
Error:
com.google.cloud.bigquery.BigQueryException: Invalid project ID 'no_app_id'. Project IDs must contain 6-63 lowercase letters, digits, or dashes. IDs must start with a letter and may not end with a dash.
at com.google.cloud.bigquery.spi.v2.HttpBigQueryRpc.translate(HttpBigQueryRpc.java:86)
at com.google.cloud.bigquery.spi.v2.HttpBigQueryRpc.create(HttpBigQueryRpc.java:170)
at com.google.cloud.bigquery.BigQueryImpl$3.call(BigQueryImpl.java:208)
...
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 400
{ "code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid project ID 'no_app_id'. Project IDs must contain 6-63 lowercase letters, digits, or dashes. IDs must start with a letter and may not end with a dash.",
"reason" : "invalid"
} ],
"message" : "Invalid project ID 'no_app_id'. Project IDs must contain 6-63 lowercase letters, digits, or dashes. IDs must start with a letter and may not end with a dash."
}
Code:
package com.example.bigquery;
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.FieldValue;
import com.google.cloud.bigquery.Job;
import com.google.cloud.bigquery.JobId;
import com.google.cloud.bigquery.JobInfo;
import com.google.cloud.bigquery.QueryJobConfiguration;
import com.google.cloud.bigquery.QueryResponse;
import com.google.cloud.bigquery.QueryResult;
import java.util.List;
import java.util.UUID;
public class SimpleApp {
public void runBQ() throws Exception {
// [START create_client]
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
// [END create_client]
// [START run_query]
QueryJobConfiguration queryConfig =
QueryJobConfiguration.newBuilder(
"SELECT "
+ "APPROX_TOP_COUNT(corpus, 10) as title, "
+ "COUNT(*) as unique_words "
+ "FROM `publicdata.samples.shakespeare`;")
// Use standard SQL syntax for queries.
// See: https://cloud.google.com/bigquery/sql-reference/
.setUseLegacySql(false)
.build();
// Create a job ID so that we can safely retry.
JobId jobId = JobId.of(UUID.randomUUID().toString());
Job queryJob = bigquery.create(JobInfo.newBuilder(queryConfig).setJobId(jobId).build());
// Wait for the query to complete.
queryJob = queryJob.waitFor();
// Check for errors
if (queryJob == null) {
throw new RuntimeException("Job no longer exists");
} else if (queryJob.getStatus().getError() != null) {
// You can also look at queryJob.getStatus().getExecutionErrors() for all
// errors, not just the latest one.
throw new RuntimeException(queryJob.getStatus().getError().toString());
}
// Get the results.
QueryResponse response = bigquery.getQueryResults(jobId);
// [END run_query]
// [START print_results]
QueryResult result = response.getResult();
// Print all pages of the results.
while (result != null) {
for (List<FieldValue> row : result.iterateAll()) {
List<FieldValue> titles = row.get(0).getRepeatedValue();
System.out.println("titles:");
for (FieldValue titleValue : titles) {
List<FieldValue> titleRecord = titleValue.getRecordValue();
String title = titleRecord.get(0).getStringValue();
long uniqueWords = titleRecord.get(1).getLongValue();
System.out.printf("\t%s: %d\n", title, uniqueWords);
}
long uniqueWords = row.get(1).getLongValue();
System.out.printf("total unique words: %d\n", uniqueWords);
}
result = result.getNextPage();
}
// [END print_results]
}
}
From the looks of your error code, it's probably due to your project ID not being set: "no_app_id". Here is how to set your project ID for app engine: https://developers.google.com/eclipse/docs/appengine_appid_version.

Related Links

Hibernate with long text column with Oracle and PostgreSQL
Cassandra batch query vs single insert performance
Why it is possible to directly use Interface's method
JPA Persisting wrong Calendar date
Quartz Scheduler - Standby Until Following Day
PSP socket from a MAC address?
How to make my for loop not to show message until it reach the end of array [closed]
Is adding too many stubbed methods a reason for adding special constructor just for tests? (over mocking)
On Camunda-Spring Integration TaskDefinition is null for active task
How to install maven on microsoft Azure (app servies)
Make a Map content final after initialization, but not the map itself
Why this particular code generates “ambiguous method call” error in Android Studio?
How implement external CSS & Font in a java epub library – Paul Siegmann
Java : Is String.replace GC overhead too much?
General Architectural Design around Payment Gateways
Google Cloud Vision API - send base64 encoded image in POST request

Categories

HOME
hook
openstack
magnific-popup
plot
iot
fingerprint
ios-charts
bs4
slick-slider
vault
floating-action-button
alignment
orchardcms
fortumo
event-handling
decimal
iolanguage
graphlab
jsdoc
ab-testing
oracle-coherence
dbext
nas
reverse-proxy
tokenize
cloudhub
trading
numerical-methods
microsoft-sync-framework
su
url-scheme
traffic
elasticsearch-ruby
gitignore
gsoap
tinymce-4
windows-dev-center
android-nestedscrollview
atl
appfabric
main
lto
elasticsearch-plugin
eclipse-scout
dynamic-reports
checkboxlist
flashair
alphabet
mu
query-performance
synchronous
xcb
visual-c++-2008
ableton-live
log4c
phishing
skobbler-maps
xml-attribute
paypal-express
plottable.js
pagedlist
maven-tomcat-plugin
lib.web.mvc
cannon.js
qdialog
wireshark-dissector
pundit
wyam
dukescript
sysinternals
graph-drawing
angular-local-storage
clipperlib
streambase
qpainter
relocation
device-manager
code-access-security
bitcoinj
heisenbug
htmlcleaner
valuechangelistener
resty-gwt
oam
dir
pygit2
pvrtc
sublist
rdoc
cascalog
data-loss
f#-powerpack
calling-convention
android-sdk-2.1
lpeg
createwindow
asp.net-mvc-areas
gallio

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App