Skip to content

Commit 82a535d

Browse files
feat(duckDB): Fix code after rebase as bytestring handling was changed in generator
1 parent 8d3e8bf commit 82a535d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

sqlglot/dialects/duckdb.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,10 +1217,18 @@ def startswith_sql(self, expression: exp.StartsWith) -> str:
12171217

12181218
expr = annotate_types(expr, dialect=self.dialect)
12191219

1220-
if this.type and not this.is_type(exp.DataType.Type.VARCHAR, exp.DataType.Type.UNKNOWN):
1220+
if isinstance(expression.this, exp.ByteString):
1221+
expression.this.replace(exp.Literal.string(expression.this.this))
1222+
elif this.type and not this.is_type(
1223+
exp.DataType.Type.VARCHAR, exp.DataType.Type.UNKNOWN
1224+
):
12211225
expression.this.replace(exp.cast(expression.this, exp.DataType.Type.VARCHAR))
12221226

1223-
if expr.type and not expr.is_type(exp.DataType.Type.VARCHAR, exp.DataType.Type.UNKNOWN):
1227+
if isinstance(expression.expression, exp.ByteString):
1228+
expression.expression.replace(exp.Literal.string(expression.expression.this))
1229+
elif expr.type and not expr.is_type(
1230+
exp.DataType.Type.VARCHAR, exp.DataType.Type.UNKNOWN
1231+
):
12241232
expression.expression.replace(
12251233
exp.cast(expression.expression, exp.DataType.Type.VARCHAR)
12261234
)

tests/dialects/test_bigquery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ def test_bigquery(self):
12171217
"STARTS_WITH(CAST('foo' AS BYTES), b'f')",
12181218
write={
12191219
"bigquery": "STARTS_WITH(CAST('foo' AS BYTES), b'f')",
1220-
"duckdb": "STARTS_WITH(CAST(CAST('foo' AS BLOB) AS TEXT), e'f')",
1220+
"duckdb": "STARTS_WITH(CAST(CAST('foo' AS BLOB) AS TEXT), 'f')",
12211221
},
12221222
)
12231223
self.validate_all(

0 commit comments

Comments
 (0)