Dialogflow 与 BigQuery 的集成 - 将整数参数传递给 BQ
Posted
技术标签:
【中文标题】Dialogflow 与 BigQuery 的集成 - 将整数参数传递给 BQ【英文标题】:Dialogflow integration with BigQuery - Passing integer parameters to BQ 【发布时间】:2019-03-02 10:47:35 【问题描述】:我正在创建一个从 BigQuery 检索数据的聊天机器人,但我在 Dialogflow 中遇到了数据类型问题:
Dialogflow 参数为:Rating (@sys.number-int)、Country (string)、Department (String)
当我执行以下代码时,似乎 bigquery 正在接收作为字符串的评级(国家和部门是字符串在 BigQuery 中工作正常),所以这就是我尝试 CAST 但没有运气的原因。
谁能帮我将 INT64 变量从 Dialogflow 传递给 BigQuery?
function buyAgainPredictor(agent)
const OPTIONS =
query: 'WITH pred_table AS (SELECT CAST(`request.body.queryResult.outputContexts[0].parameters.Rating´ AS INT64) as Rating, "request.body.queryResult.outputContexts[0].parameters.Department" as Department, "request.body.queryResult.outputContexts[0].parameters.Country" as Country)' +
'SELECT cast(predicted_label as INT64) as predicted_label ' +
'FROM ML.PREDICT(MODEL Customer_feedback.recommend_model, TABLE pred_table)',
timeoutMs: 10000,
useLegacySql: false,
queryParameters:
DialogFlow parameter definition
【问题讨论】:
你认为它为什么将它作为字符串接收? 【参考方案1】:您没有替换字符串中的变量。在query
试试这个:
`WITH pred_table AS (
SELECT $request.body.queryResult.outputContexts[0].parameters.Rating as Rating,
"$request.body.queryResult.outputContexts[0].parameters.Department" as Department,
"$request.body.queryResult.outputContexts[0].parameters.Country" as Country)
SELECT cast(predicted_label as INT64) as predicted_label
FROM ML.PREDICT(MODEL Customer_feedback.recommend_model, TABLE pred_table)`
通常,您不想在 SQL 查询 (SQL injection) 中使用用户输入,请查看 parameterized queries 上的文档。考虑到这一点,你可以试试这个:
const OPTIONS =
query: `WITH pred_table AS (
SELECT @rating as Rating,
@department as Department,
@country as Country)
SELECT cast(predicted_label as INT64) as predicted_label
FROM ML.PREDICT(MODEL Customer_feedback.recommend_model, TABLE pred_table)`,
timeoutMs: 10000,
useLegacySql: false,
queryParameters:
rating: parameters.Rating,
department: parameters.Department,
country: parameters.Country
【讨论】:
以上是关于Dialogflow 与 BigQuery 的集成 - 将整数参数传递给 BQ的主要内容,如果未能解决你的问题,请参考以下文章
Google 的 dialogflow 集成“dialogflow messenger”(测试版)
Dialogflow Facebook 集成未响应页面的传入消息