diff --git a/ibis/backends/duckdb/__init__.py b/ibis/backends/duckdb/__init__.py index 0380bf3206b9..64253fda183a 100644 --- a/ibis/backends/duckdb/__init__.py +++ b/ibis/backends/duckdb/__init__.py @@ -1008,12 +1008,10 @@ def list_tables( .from_(sg.table("tables", db="information_schema")) .distinct() .where( - C.table_catalog.eq(catalog).or_( - C.table_catalog.eq(sge.convert("temp")) - ), - C.table_schema.eq(database), + C.table_catalog.isin(sge.convert(catalog), sge.convert("temp")), + C.table_schema.eq(sge.convert(database)), ) - .sql(self.name, pretty=True) + .sql(self.dialect) ) out = self.con.execute(sql).fetch_arrow_table() diff --git a/ibis/backends/duckdb/compiler.py b/ibis/backends/duckdb/compiler.py index 2cc789ea360c..54c53b892117 100644 --- a/ibis/backends/duckdb/compiler.py +++ b/ibis/backends/duckdb/compiler.py @@ -238,21 +238,21 @@ def visit_MapMerge(self, op, *, left, right): def visit_ToJSONMap(self, op, *, arg): return self.if_( - self.f.json_type(arg).eq("OBJECT"), + self.f.json_type(arg).eq(sge.convert("OBJECT")), self.cast(self.cast(arg, dt.json), op.dtype), NULL, ) def visit_ToJSONArray(self, op, *, arg): return self.if_( - self.f.json_type(arg).eq("ARRAY"), + self.f.json_type(arg).eq(sge.convert("ARRAY")), self.cast(self.cast(arg, dt.json), op.dtype), NULL, ) def visit_UnwrapJSONString(self, op, *, arg): return self.if_( - self.f.json_type(arg).eq("VARCHAR"), + self.f.json_type(arg).eq(sge.convert("VARCHAR")), self.f.json_extract_string(arg, "$"), NULL, ) @@ -260,18 +260,26 @@ def visit_UnwrapJSONString(self, op, *, arg): def visit_UnwrapJSONInt64(self, op, *, arg): arg_type = self.f.json_type(arg) return self.if_( - arg_type.isin("UBIGINT", "BIGINT"), self.cast(arg, op.dtype), NULL + arg_type.isin(sge.convert("UBIGINT"), sge.convert("BIGINT")), + self.cast(arg, op.dtype), + NULL, ) def visit_UnwrapJSONFloat64(self, op, *, arg): arg_type = self.f.json_type(arg) return self.if_( - arg_type.isin("UBIGINT", "BIGINT", "DOUBLE"), self.cast(arg, op.dtype), NULL + arg_type.isin( + sge.convert("UBIGINT"), sge.convert("BIGINT"), sge.convert("DOUBLE") + ), + self.cast(arg, op.dtype), + NULL, ) def visit_UnwrapJSONBoolean(self, op, *, arg): return self.if_( - self.f.json_type(arg).eq("BOOLEAN"), self.cast(arg, op.dtype), NULL + self.f.json_type(arg).eq(sge.convert("BOOLEAN")), + self.cast(arg, op.dtype), + NULL, ) def visit_ArrayConcat(self, op, *, arg): diff --git a/ibis/backends/exasol/__init__.py b/ibis/backends/exasol/__init__.py index e9b0186b0e71..0eb1afc1664a 100644 --- a/ibis/backends/exasol/__init__.py +++ b/ibis/backends/exasol/__init__.py @@ -50,7 +50,7 @@ def version(self) -> str: query = ( sg.select("param_value") .from_(sg.table("EXA_METADATA", catalog="SYS")) - .where(C.param_name.eq("databaseProductVersion")) + .where(C.param_name.eq(sge.convert("databaseProductVersion"))) ) with self._safe_raw_sql(query) as result: [(version,)] = result.fetchall() diff --git a/ibis/backends/mysql/__init__.py b/ibis/backends/mysql/__init__.py index bbd0fa79c7f7..917f52fd7015 100644 --- a/ibis/backends/mysql/__init__.py +++ b/ibis/backends/mysql/__init__.py @@ -329,8 +329,6 @@ def list_tables( sg_db.args["quoted"] = False conditions = [C.table_schema.eq(sge.convert(table_loc.sql(self.name)))] - # conditions.append(C.table_schema.eq(table_loc)) - col = "table_name" sql = ( sg.select(col) diff --git a/ibis/backends/mysql/compiler.py b/ibis/backends/mysql/compiler.py index 66e791266c63..f4ce57ec931f 100644 --- a/ibis/backends/mysql/compiler.py +++ b/ibis/backends/mysql/compiler.py @@ -336,22 +336,28 @@ def visit_TimestampAdd(self, op, *, left, right): def visit_UnwrapJSONString(self, op, *, arg): return self.if_( - self.f.json_type(arg).eq("STRING"), self.f.json_unquote(arg), NULL + self.f.json_type(arg).eq(sge.convert("STRING")), + self.f.json_unquote(arg), + NULL, ) def visit_UnwrapJSONInt64(self, op, *, arg): return self.if_( - self.f.json_type(arg).eq("INTEGER"), self.cast(arg, op.dtype), NULL + self.f.json_type(arg).eq(sge.convert("INTEGER")), + self.cast(arg, op.dtype), + NULL, ) def visit_UnwrapJSONFloat64(self, op, *, arg): return self.if_( - self.f.json_type(arg).isin("DOUBLE", "INTEGER"), + self.f.json_type(arg).isin(sge.convert("DOUBLE"), sge.convert("INTEGER")), self.cast(arg, op.dtype), NULL, ) def visit_UnwrapJSONBoolean(self, op, *, arg): return self.if_( - self.f.json_type(arg).eq("BOOLEAN"), self.if_(arg.eq("true"), 1, 0), NULL + self.f.json_type(arg).eq(sge.convert("BOOLEAN")), + self.if_(arg.eq(sge.convert("true")), 1, 0), + NULL, ) diff --git a/ibis/backends/oracle/__init__.py b/ibis/backends/oracle/__init__.py index 2f1dc277b8b8..1107a5bc2cbc 100644 --- a/ibis/backends/oracle/__init__.py +++ b/ibis/backends/oracle/__init__.py @@ -550,10 +550,10 @@ def transformer(node): C.data_type, C.data_precision, C.data_scale, - C.nullable.eq("Y"), + C.nullable.eq(sge.convert("Y")), ) .from_("all_tab_columns") - .where(C.table_name.eq(name)) + .where(C.table_name.eq(sge.convert(name))) .order_by(C.column_id) .sql(dialect) ) diff --git a/ibis/backends/postgres/__init__.py b/ibis/backends/postgres/__init__.py index bdd8f2467967..1deaa654b895 100644 --- a/ibis/backends/postgres/__init__.py +++ b/ibis/backends/postgres/__init__.py @@ -352,11 +352,11 @@ def list_tables( if (db := table_loc.args["db"]) is not None: db.args["quoted"] = False db = db.sql(dialect=self.name) - conditions.append(C.table_schema.eq(db)) + conditions.append(C.table_schema.eq(sge.convert(db))) if (catalog := table_loc.args["catalog"]) is not None: catalog.args["quoted"] = False catalog = catalog.sql(dialect=self.name) - conditions.append(C.table_catalog.eq(catalog)) + conditions.append(C.table_catalog.eq(sge.convert(catalog))) sql = ( sg.select("table_name") @@ -385,7 +385,7 @@ def _fetch_temp_tables(self): sg.select("table_name") .from_(sg.table("tables", db="information_schema")) .distinct() - .where(C.table_type.eq("LOCAL TEMPORARY")) + .where(C.table_type.eq(sge.convert("LOCAL TEMPORARY"))) .sql(self.dialect) ) @@ -434,7 +434,7 @@ def function(self, name: str, *, database: str | None = None) -> Callable: p = ColGen(table="p") f = self.compiler.f - predicates = [p.proname.eq(name)] + predicates = [p.proname.eq(sge.convert(name))] if database is not None: predicates.append(n.nspname.rlike(sge.convert(f"^({database})$"))) @@ -585,8 +585,8 @@ def get_schema( .where( a.attnum > 0, sg.not_(a.attisdropped), - n.nspname.eq(database) if database is not None else TRUE, - c.relname.eq(name), + n.nspname.eq(sge.convert(database)) if database is not None else TRUE, + c.relname.eq(sge.convert(name)), ) .order_by(a.attnum) ) diff --git a/ibis/backends/postgres/compiler.py b/ibis/backends/postgres/compiler.py index 2e74f380ffc9..496119949689 100644 --- a/ibis/backends/postgres/compiler.py +++ b/ibis/backends/postgres/compiler.py @@ -319,7 +319,7 @@ def visit_StructField(self, op, *, arg, field): def visit_UnwrapJSONString(self, op, *, arg): return self.if_( - self.f.json_typeof(arg).eq("string"), + self.f.json_typeof(arg).eq(sge.convert("string")), self.f.json_extract_path_text( arg, # this is apparently how you pass in no additional arguments to @@ -336,7 +336,7 @@ def visit_UnwrapJSONInt64(self, op, *, arg): arg, sge.Var(this="VARIADIC ARRAY[]::TEXT[]") ) return self.if_( - self.f.json_typeof(arg).eq("number"), + self.f.json_typeof(arg).eq(sge.convert("number")), self.cast( self.if_(self.f.regexp_like(text, r"^\d+$", "g"), text, NULL), op.dtype, @@ -349,12 +349,14 @@ def visit_UnwrapJSONFloat64(self, op, *, arg): arg, sge.Var(this="VARIADIC ARRAY[]::TEXT[]") ) return self.if_( - self.f.json_typeof(arg).eq("number"), self.cast(text, op.dtype), NULL + self.f.json_typeof(arg).eq(sge.convert("number")), + self.cast(text, op.dtype), + NULL, ) def visit_UnwrapJSONBoolean(self, op, *, arg): return self.if_( - self.f.json_typeof(arg).eq("boolean"), + self.f.json_typeof(arg).eq(sge.convert("boolean")), self.cast( self.f.json_extract_path_text( arg, sge.Var(this="VARIADIC ARRAY[]::TEXT[]") diff --git a/ibis/backends/sqlite/__init__.py b/ibis/backends/sqlite/__init__.py index 6989bff9e3da..960729ea894d 100644 --- a/ibis/backends/sqlite/__init__.py +++ b/ibis/backends/sqlite/__init__.py @@ -145,14 +145,14 @@ def list_tables( sg.select("name") .from_(F.pragma_table_list()) .where( - C.schema.eq(database), - C.type.isin("table", "view"), + C.schema.eq(sge.convert(database)), + C.type.isin(sge.convert("table"), sge.convert("view")), ~( C.name.isin( - "sqlite_schema", - "sqlite_master", - "sqlite_temp_schema", - "sqlite_temp_master", + sge.convert("sqlite_schema"), + sge.convert("sqlite_master"), + sge.convert("sqlite_temp_schema"), + sge.convert("sqlite_temp_master"), ) ), ) diff --git a/ibis/backends/sqlite/compiler.py b/ibis/backends/sqlite/compiler.py index c2232a885669..50cab3700728 100644 --- a/ibis/backends/sqlite/compiler.py +++ b/ibis/backends/sqlite/compiler.py @@ -223,19 +223,21 @@ def _visit_arg_reduction(self, func, op, *, arg, key, where): def visit_UnwrapJSONString(self, op, *, arg): return self.if_( - self.f.json_type(arg).eq("text"), self.f.json_extract_scalar(arg, "$"), NULL + self.f.json_type(arg).eq(sge.convert("text")), + self.f.json_extract_scalar(arg, "$"), + NULL, ) def visit_UnwrapJSONInt64(self, op, *, arg): return self.if_( - self.f.json_type(arg).eq("integer"), + self.f.json_type(arg).eq(sge.convert("integer")), self.cast(self.f.json_extract_scalar(arg, "$"), op.dtype), NULL, ) def visit_UnwrapJSONFloat64(self, op, *, arg): return self.if_( - self.f.json_type(arg).isin("integer", "real"), + self.f.json_type(arg).isin(sge.convert("integer"), sge.convert("real")), self.cast(self.f.json_extract_scalar(arg, "$"), op.dtype), NULL, ) @@ -244,7 +246,7 @@ def visit_UnwrapJSONBoolean(self, op, *, arg): return self.if_( # isin doesn't work here, with a strange error from sqlite about a # misused row value - self.f.json_type(arg).isin("true", "false"), + self.f.json_type(arg).isin(sge.convert("true"), sge.convert("false")), self.cast(self.f.json_extract_scalar(arg, "$"), dt.int64), NULL, )