1
Python API를 사용하여 간단한 Google BigQuery 애플리케이션을 설정하려고합니다. 나는 퀵 스타트 가이드를 따랐다 :Google BigQuery - Python 쿼리가 올바르게 구문 분석되지 않습니다.
import argparse
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from oauth2client.client import GoogleCredentials
def main(project_id):
print "hello"
# [START build_service]
# Grab the application's default credentials from the environment.
credentials = GoogleCredentials.get_application_default()
# Construct the service object for interacting with the BigQuery API.
bigquery_service = build('bigquery', 'v2', credentials=credentials)
# [END build_service]
query_request = bigquery_service.jobs()
query_data = {
'query': (
'SELECT ticker,close1'
'FROM Data.data_7 '
'WHERE ticker = "GTIM"'
'LIMIT 10')
}
query_response = query_request.query(
projectId=project_id,
body=query_data).execute()
print('Query Results:')
for row in query_response['rows']:
print('\t'.join(field['v'] for field in row['f']))
main("sqlserver-1384")
위 쿼리를 성공적으로 실행할 수 있었다. 그러나 때마다 나는 그것을 변경 :
'query': (
'SELECT ticker,close1'
'FROM Data.data_7 '
'ORDER BY close1 ASC'
'LIMIT 10')
}
나는 다음과 같은 오류 얻을 :
Traceback (most recent call last):
File "server1.py", line 57, in <module>
main("sqlserver-1384")
File "server1.py", line 50, in main
body=query_data).execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/oauth2client/util.py", line 135, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/googleapiclient/http.py", line 832, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/bigquery/v2/projects/sqlserver-1384/queries?alt=json returned "Encountered " <ID> "ASCLIMIT "" at line 1, column 54.
Was expecting:
<EOF>">
내 형식에 문제가 있습니까? Google BigQuery 웹 콘솔에서 동일한 쿼리를 실행했는데 정상적으로 작동했습니다. 쿼리 문자열은 파이썬 파서에 의해 연결된 도착하면
당신은 유효한 BQ의 SQL없는 단어ASCLIMIT
남아있어, 당신
정답 및 수정 해 주셔서 감사합니다. 허용되는 즉시 정답으로 표시됩니다. –