|
21 | 21 | schema_from_bigquery_table, |
22 | 22 | ) |
23 | 23 | from bigframes_vendored.ibis.backends.bigquery.datatypes import BigQuerySchema |
24 | | -from bigframes_vendored.ibis.backends.bigquery.udf.core import ( |
25 | | - PythonToJavaScriptTranslator, |
26 | | -) |
27 | 24 | from bigframes_vendored.ibis.backends.sql import SQLBackend |
28 | 25 | from bigframes_vendored.ibis.backends.sql.compilers import BigQueryCompiler |
29 | 26 | from bigframes_vendored.ibis.backends.sql.datatypes import BigQueryType |
@@ -731,15 +728,7 @@ def compile( |
731 | 728 | ): |
732 | 729 | """Compile an Ibis expression to a SQL string.""" |
733 | 730 | query = self._to_sqlglot(expr, limit=limit, params=params, **kwargs) |
734 | | - udf_sources = [] |
735 | | - for udf_node in expr.op().find(ops.ScalarUDF): |
736 | | - compile_func = getattr( |
737 | | - self, f"_compile_{udf_node.__input_type__.name.lower()}_udf" |
738 | | - ) |
739 | | - if sql := compile_func(udf_node): |
740 | | - udf_sources.append(sql.sql(self.name, pretty=True)) |
741 | | - |
742 | | - sql = ";\n".join([*udf_sources, query.sql(dialect=self.name, pretty=True)]) |
| 731 | + sql = query.sql(dialect=self.name, pretty=True) |
743 | 732 | self._log(sql) |
744 | 733 | return sql |
745 | 734 |
|
@@ -1186,68 +1175,6 @@ def _clean_up_cached_table(self, name): |
1186 | 1175 | force=True, |
1187 | 1176 | ) |
1188 | 1177 |
|
1189 | | - def _get_udf_source(self, udf_node: ops.ScalarUDF): |
1190 | | - name = type(udf_node).__name__ |
1191 | | - type_mapper = self.compiler.udf_type_mapper |
1192 | | - |
1193 | | - body = PythonToJavaScriptTranslator(udf_node.__func__).compile() |
1194 | | - config = udf_node.__config__ |
1195 | | - libraries = config.get("libraries", []) |
1196 | | - |
1197 | | - signature = [ |
1198 | | - sge.ColumnDef( |
1199 | | - this=sg.to_identifier(name, quoted=self.compiler.quoted), |
1200 | | - kind=type_mapper.from_ibis(param.annotation.pattern.dtype), |
1201 | | - ) |
1202 | | - for name, param in udf_node.__signature__.parameters.items() |
1203 | | - ] |
1204 | | - |
1205 | | - lines = ['"""'] |
1206 | | - |
1207 | | - if config.get("strict", True): |
1208 | | - lines.append('"use strict";') |
1209 | | - |
1210 | | - lines += [ |
1211 | | - body, |
1212 | | - "", |
1213 | | - f"return {udf_node.__func_name__}({', '.join(udf_node.argnames)});", |
1214 | | - '"""', |
1215 | | - ] |
1216 | | - |
1217 | | - func = sge.Create( |
1218 | | - kind="FUNCTION", |
1219 | | - this=sge.UserDefinedFunction( |
1220 | | - this=sg.to_identifier(name), expressions=signature, wrapped=True |
1221 | | - ), |
1222 | | - # not exactly what I had in mind, but it works |
1223 | | - # |
1224 | | - # quoting is too simplistic to handle multiline strings |
1225 | | - expression=sge.Var(this="\n".join(lines)), |
1226 | | - exists=False, |
1227 | | - properties=sge.Properties( |
1228 | | - expressions=[ |
1229 | | - sge.TemporaryProperty(), |
1230 | | - sge.ReturnsProperty(this=type_mapper.from_ibis(udf_node.dtype)), |
1231 | | - sge.StabilityProperty( |
1232 | | - this="IMMUTABLE" if config.get("determinism") else "VOLATILE" |
1233 | | - ), |
1234 | | - sge.LanguageProperty(this=sg.to_identifier("js")), |
1235 | | - ] |
1236 | | - + [ |
1237 | | - sge.Property( |
1238 | | - this=sg.to_identifier("library"), |
1239 | | - value=self.compiler.f.array(*libraries), |
1240 | | - ) |
1241 | | - ] |
1242 | | - * bool(libraries) |
1243 | | - ), |
1244 | | - ) |
1245 | | - |
1246 | | - return func |
1247 | | - |
1248 | | - def _compile_python_udf(self, udf_node: ops.ScalarUDF) -> None: |
1249 | | - return self._get_udf_source(udf_node) |
1250 | | - |
1251 | 1178 | def _register_udfs(self, expr: ir.Expr) -> None: |
1252 | 1179 | """No op because UDFs made with CREATE TEMPORARY FUNCTION must be followed by a query.""" |
1253 | 1180 |
|
|
0 commit comments