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

Tomcat 404 when using servlets
JSONArray array = new JSONArray(string_of_json_array);
Foreign key issue MySQL
How do I not allow duplicates to be added into an Binary Search Tree?
Weblogic Throttle threads for #WebService but allow for others/#Path
Populating Array from File input
Change design item of GridView, how? - Android
Create guacamole users
Google AppEngine - How to set default Charset / file-encoding (to UTF-8) for Google AppEngine
Are wildcards allowed in the Log4j (via Spring Boot Logging) logging.level property?
Android / Dalvik VM Cannot Find Native Framework Methods [duplicate]
JavaFX compiling but nodes not appearing in application
handling application and business failure scenarios for a java REST API using exceptions
Detect object changes for java serialization
Database Query returning inconsistent result when using Tomcat JDBC pool
How do I change font type but not size in java?

Categories

HOME
client
wso2
netbeans
dot
octobercms
mean-stack
sqlite-net-extensions
ezpublish
yum
fancybox
google-translate
kibana-4
rascal
modx-revolution
export-to-csv
etl
google-apps-marketplace
google-cloud-ml
event-handling
ibm-odm
flask-wtforms
fatal-error
beyondcompare
swiftlint
paging
opencover
jasonette
jquery-ajaxq
functional-testing
tar
pepper
centos6.5
neo4j-spatial
log4js-node
compatibility
atlassian-crucible
nouislider
lightswitch-2013
semantic-versioning
data-manipulation
copying
caret
stringtemplate
force-layout
jmonkeyengine
revolution-slider
mixture-model
http-live-streaming
android-mediaprojection
qcombobox
pubmed
sage-one
brightcove
pillow
dynamics-sl
vtigercrm
setuptools
angular-cache
gridpane
autorest
jwplayer7
simplewebrtc
pickadate
r-tree
thredds
cyclomatic-complexity
ruby-2.2
deis
arcanist
apache-commons-fileupload
facebook-graph-api-v2.4
c3
rdtsc
document-classification
typeof
funcunit
balanced-payments
terminal-services
farseer
ruby-datamapper
dataservice
back-stack
gridcontrol
enterprisedb
cassini-dev
delphi-6
automount
ohm
subgurim-maps
genshi
coredump
yui-datatable
oncheckedchanged
locate
gamma
mozilla-prism
jquery-ui-droppable
vc90
eqatec
simpletest
putchar
post-build
document-conversion

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile