-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow field name declaration in ROW literal #25261
base: master
Are you sure you want to change the base?
Conversation
95e89ed
to
6cbfff3
Compare
I like this, but I would use the following syntax to make it similar to how the implicit row in the SELECT clause is constructed:
That way, the only syntactic difference with the SELECT clause, is that the fields are wrapped in |
As another example, the syntax I suggested above makes these two equivalent:
|
I'm working on the syntax change, but for VALUES the names of the relation aren't sourced from the rows. Today you can name row fields with a cast in values, but they don't effect the values column aliases:
I'm guessing that can be improved, but I have no idea how... work for follow up |
129dee6
to
85c7a67
Compare
e9d221a
to
fb992f3
Compare
Add support for `row(a 1, b 2)` instead of the much more complex `cast(row(1, 2) as row(a integer, b integer))`.
fb992f3
to
652c533
Compare
Is this expected:
field names are uppercased |
Yes, that's standard SQL identifier canonicalization behavior. |
Syntax looks good. |
@martint this is unfortunate if you want to use this new syntax to produce a JSON like:
|
What if you quote the identifiers? |
that works but not super obvious (note " vs ' - ' doesn't work) |
|
It becomes more obvious when you think about how identifiers work. The type of |
@wendigo I agree the changing of case really sucks, but it is a existing issue. |
|
||
assertThat((boolean) typeOperators.getIndeterminateOperator(emptyRowType, simpleConvention(FAIL_ON_NULL, BLOCK_POSITION_NOT_NULL)) | ||
.invokeExact(singleEmptyRow, 0)).isFalse(); | ||
assertThat((Boolean) typeOperators.getEqualOperator(emptyRowType, simpleConvention(NULLABLE_RETURN, BLOCK_POSITION_NOT_NULL, BLOCK_POSITION_NOT_NULL)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this one have a different convention?
@@ -574,7 +574,7 @@ primaryExpression | |||
| QUESTION_MARK #parameter | |||
| POSITION '(' valueExpression IN valueExpression ')' #position | |||
| '(' expression (',' expression)+ ')' #rowConstructor | |||
| ROW '(' expression (',' expression)* ')' #rowConstructor | |||
| ROW '(' fieldConstructor (',' fieldConstructor)* ')' #rowConstructor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix alignment of the label
@@ -646,6 +646,10 @@ primaryExpression | |||
')' #jsonArray | |||
; | |||
|
|||
fieldConstructor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe name this rowField
return node.items().stream() | ||
.map(child -> process(child, context)) | ||
.collect(joining(", ", "ROW (", ")")); | ||
List<RowType.Field> fieldTypes = ((RowType) node.type()).getFields(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the IR Row
type should override type()
to return RowType
so that callers don't need to cast
@@ -33,10 +33,9 @@ public record Row(List<Expression> items) | |||
items = ImmutableList.copyOf(items); | |||
} | |||
|
|||
@Override | |||
public Type type() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep this and change signature to RowType
@@ -141,7 +142,7 @@ public static Values values(Row... row) | |||
|
|||
public static Row row(Expression... values) | |||
{ | |||
return new Row(ImmutableList.copyOf(values)); | |||
return new Row(Arrays.stream(values).map(Row.Field::new).collect(Collectors.toList())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use .toList()
List<Type> types = node.getItems().stream() | ||
.map(child -> process(child, context)) | ||
List<RowType.Field> fields = node.getFields().stream() | ||
.map(field -> new RowType.Field(field.getName().map(Identifier::getCanonicalValue), process(field.getExpression(), context))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap arguments?
if (node.getName().isPresent()) { | ||
process(node.getName().get(), context); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node.getName().ifPresent(name -> process(name, context));
if (name.isPresent()) { | ||
builder.append(name.get()); | ||
builder.append(" "); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name.ifPresent(x -> builder.append(x).append(" "));
Description
Add support for
row(a 1, b 2)
instead of the much more complexcast(row(1, 2) as row(a integer, b integer))
. The old syntax is particularly annoying because you have to repeat the types for the fields.Release notes
(X) Release notes are required, with the following suggested text: