簡體   English   中英

文字和別名 bigquery 之間缺少空格

[英]Missing whitespace between literal and alias bigquery

我有這個 python 代碼:

def insert_actions_table(client, json, uuid):
    session_id = (json['session_id'])
    if(session_id == None):
        session_id =  '"Null"'
    timestamp = str(json['timeStamp'])
    new_category = '"' + str((json['category']).replace("-", "_")) + '"'
    action = '"' + str(json['action'].replace("-", "_")) + '"'
    new_current_url = json['current_url'].replace("-", "_")
    if(len(new_current_url) == 0):
        new_current_url = '"Null"'
    if(new_current_url[0] == '/'):
        new_current_url = new_current_url[1:]
    query_text = f"""
    INSERT `insights-30062021.em_first_try._actions` (_session_id, _timestamp, _category, _action, current_url, _uuid)
    VALUES ({session_id}, {timestamp}, {new_category}, {action}, {new_current_url}, {uuid})
    """
    query_job = client.query(query_text)

    # Wait for query job to finish.
    query_job.result()

    print(f"DML query modified {query_job.num_dml_affected_rows} rows.")
    return query_job.num_dml_affected_rows

但我得到這個錯誤:

google.api_core.exceptions.BadRequest:400 語法錯誤:[3:75] 處的文字和別名之間缺少空格

謝謝您的幫助。

當我嘗試在 bigquery 中使用插入代碼時,我遇到了類似的錯誤。 也許您可以嘗試添加“”,就像“{YOUR_VARIABLE}”一樣。

例如:

query_text = f"""
INSERT `insights-30062021.em_first_try._actions` 
(_session_id, _timestamp, _category, _action, current_url, _uuid)
VALUES ("{session_id}", "{timestamp}", "{new_category}", "{action}", "{new_current_url}", "{uuid}")
"""

此外,當變量類型不適合您的 bigquery 表中的架構時,可能會發生錯誤。

您可以嘗試更改whitespice設置。 為此,打開tslint.json並設置 false whitespice 設置。

"whitespace": [
      false,
         ...     ],

注意:不要忘記在此更改后重新啟動應用程序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM