Ich habe bereits eine Einführung zu diesem Thema gelesen, aber dieser Code wurde nicht ausgeführt. Ich habe die Tabelle 'product_flat_index' im Projekt erstellt und diese Funktion fügt das Abfrageergebnis zu dieser Tabelle hinzu. Aber es ist nicht gelaufen.Google Bigquery API: Wie fügen Sie eine Ergebnisabfrage zur Tabelle hinzu?
def insertValues(service):
project_id = "598330041668"
dataset_id = 'recommendation_001'
table_id = 'product_flat_index'
# [START run_query]
query = ('SELECT sku, SUM(sales) AS sales, COUNT(sales) AS sales_frequency, SUM(views) AS views,'
'SUM(carts) AS carts, SUM(sales)/SUM(carts) AS sales_effective_rate,AVG(rating) AS rating,'
'SUM(comments) AS comments '
'FROM recommendation_001.user_input_product '
'GROUP BY sku '
)
configuration = {
"query": query,
}
body = {
"configuration":
{
"query": configuration,
"destinationTable": {
"projectId": project_id,
"datasetId": dataset_id,
"tableId": table_id
},
"createDisposition": "CREATE_IF_NEEDED",
"writeDisposition": "WRITE_APPEND",
},
}
return service.jobs().insert(
projectId=project_id,
body=body
).execute()
# [END run_query]