我为两个字符串列之间的字符串匹配百分比 (0-1) 创建了 UDF,当我执行以下查询时遇到此错误。我想执行此代码以获取名称匹配算法以显示概率算法从 0- 1 值。我创建了两个函数并在此函数中定义了两个字符串列。CREATE OR REPLACE FUNCTION `rep-ds-us.nboorla.similarity`(name STRING, to_name STRING) RETURNS INT64 LANGUAGE js AS """/* * Data Quality Function - Fuzzy Matching * dq_fm_LevenshteinDistance * Based off of https://gist.github.com/andrei-m/982927 * input: Two strings to compare the edit distance of. * returns: Integer of the edit distance. */var a = in_a.toLowerCase();var b = in_b.toLowerCase(); if(a.length == 0) return b.length; if(b.length == 0) return a.length;var matrix = [];// increment along the first column of each rowvar i;for(i = 0; i <= b.length; i++){ matrix[i] = [i];}// increment each column in the first rowvar j;for(j = 0; j <= a.length; j++){ matrix[0][j] = j;}// Fill in the rest of the matrixfor(i = 1; i <= b.length; i++){ for(j = 1; j <= a.length; j++){ if(b.charAt(i-1) == a.charAt(j-1)){ matrix[i][j] = matrix[i-1][j-1]; } else { matrix[i][j] = Math.min(matrix[i-1][j-1] + 1, // substitution Math.min(matrix[i][j-1] + 1, // insertion matrix[i-1][j] + 1)); // deletion } }}return matrix[b.length][a.length];""";CREATE OR REPLACE FUNCTION `rep-ds-us.nboorla.conf`(name STRING, to_name STRING) AS (/* * Data Quality Function - Fuzzy Matching * dq_fm_ldist_ratio * input: Two strings to compare. * returns: The Levenshtein similarity ratio. */(LENGTH(name) + LENGTH(to_name) - `rep-ds-us.nboorla.similarity`(name, to_name)) / (LENGTH(name) + LENGTH(to_name)));select t1.name,t2.to_name,`rep-ds-us.nboorla.conf`(t1.name,t2.to_name)from `rep-ds-us.r4e_mongo.ratings` t1 JOIN `rep-ds-us.r4e_mongo.mongo_repbiz_request_reviews` t2 on t2.id=t1.id limit 10但它给了我以下错误Query error: ReferenceError: in_a is not defined at UDF$1(STRING, STRING) line 9, columns 8-9 at [52:1]我错过了什么吗?
1 回答
四季花海
TA贡献1811条经验 获得超5个赞
它给我以下错误
查询错误:ReferenceError: in_a is not defined at UDF$1(STRING, STRING) line 9, columns 8-9 at [52:1]
我错过了什么吗?
您至少应该修复第一个函数的签名,如下所示
CREATE OR REPLACE FUNCTION `rep-ds-us.nboorla.similarity`(in_a STRING, in_b STRING) RETURNS INT64 LANGUAGE js AS """
笔记; 以上回答了您当前的具体问题,可能无法解决与您使用的代码相关的任何未来问题。
添加回答
举报
0/150
提交
取消