Change RowExpressionFormatter output to be closer to valid SQL#16335
Change RowExpressionFormatter output to be closer to valid SQL#16335rongrong merged 1 commit intoprestodb:masterfrom
Conversation
|
If you want them to be valid prestoSQL they should be in the format of |
0d148d1 to
10eb5de
Compare
done |
There was a problem hiding this comment.
Why is varbinary treated differently rather than using varbinary'xxx'?
There was a problem hiding this comment.
It seems like using TypeConstructor on varbinary takes the UTF-8 encoded version of the string as the binary literal, instead of reading it like a hex string. For example, when I run SELECT varbinary'abc123', x'abc123', varbinary'😎' on a local Presto server, I get
presto:sf1> SELECT varbinary'abc123', x'abc123', varbinary'😎';
_col0 | _col1 | _col2
-------------------+----------+-------------
61 62 63 31 32 33 | ab c1 23 | f0 9f 98 8e
I'm not sure if this is intentional behavior or not, but since varbinary literals are output as hex strings, I needed this workaround.
There was a problem hiding this comment.
A better way of doing this might be to change the ConstantExpression.toString() rather than putting this complex logic here.
There was a problem hiding this comment.
I moved it into a function LiteralInterpreter.evaluateToString(), since turning the constant to a string requires the relevant ConnectorSession and LiteralInterpreter.evaluate() contains similar logic. Thoughts?
There was a problem hiding this comment.
Sorry I didn't pay close attention. If it's not possible to move this to ConstantExpression, let's keep the logic in RowExpressionFormatter. Thanks!
There was a problem hiding this comment.
You can get the type name generically with type.getTypeSignature().getBase()
There was a problem hiding this comment.
No space between type and value
There was a problem hiding this comment.
It seems like a space is allowed:
presto:sf1> SELECT bigint'5', TYPEOF(bigint'5'), bigint '5', TYPEOF(bigint '5');
_col0 | _col1 | _col2 | _col3
-------+--------+-------+--------
5 | bigint | 5 | bigint
Is it better to have no space anyways?
92c1df1 to
9469ccf
Compare
RowExpressionFormatter outputs the type before any constant (e.g BIGINT 5) for debugging purposes. This is not valid SQL, so the constant is now output with TypeConstructor (e.g BIGINT'5'), except for VARBINARY constants, which use the binary literal syntax (e.g. X'abc123'). RowExpressionFormatter outputs LIKE expressions such as column LIKE 'pattern%' as LIKE(column, CAST(VARCHAR pattern% as LikeExpression)) and LIKE expressions with ESCAPE, such as column LIKE '$_pattern%' ESCAPE '$' as LIKE(column, LIKE_PATTERN(VARCHAR pattern%, VARCHAR $)) The output for like expressions was changed to be valid SQL.
RowExpressionFormatteroutputs the type before any constant(e.g
BIGINT 5) for debugging purposes. This is not valid SQL,so the constant is now output with
TypeConstructor(e.gBIGINT'5'),except for
VARBINARYconstants, which use the binary literalsyntax (e.g.
X'abc123').RowExpressionFormatteroutputsLIKEexpressions such ascolumn LIKE 'pattern%'as
LIKE(column, CAST(VARCHAR pattern% as LikeExpression))and
LIKEexpressions withESCAPE, such ascolumn LIKE '$_pattern%' ESCAPE '$'as
LIKE(column, LIKE_PATTERN(VARCHAR pattern%, VARCHAR $))The output for
LIKEexpressions was changed to be valid SQL.Test plan - unit tests