|
27 | 27 | import io.trino.spi.type.DecimalParseResult;
|
28 | 28 | import io.trino.spi.type.DecimalType;
|
29 | 29 | import io.trino.spi.type.Decimals;
|
| 30 | +import io.trino.spi.type.MapType; |
30 | 31 | import io.trino.spi.type.RowType;
|
31 | 32 | import io.trino.spi.type.TimeType;
|
32 | 33 | import io.trino.spi.type.TimeWithTimeZoneType;
|
|
101 | 102 | import io.trino.sql.tree.LocalTimestamp;
|
102 | 103 | import io.trino.sql.tree.LogicalExpression;
|
103 | 104 | import io.trino.sql.tree.LongLiteral;
|
| 105 | +import io.trino.sql.tree.MapLiteral; |
| 106 | +import io.trino.sql.tree.MapLiteral.EntryLiteral; |
104 | 107 | import io.trino.sql.tree.NodeRef;
|
105 | 108 | import io.trino.sql.tree.NotExpression;
|
106 | 109 | import io.trino.sql.tree.NullIfExpression;
|
|
119 | 122 | import io.trino.type.JsonPath2016Type;
|
120 | 123 | import io.trino.type.UnknownType;
|
121 | 124 |
|
| 125 | +import java.util.ArrayList; |
122 | 126 | import java.util.Arrays;
|
123 | 127 | import java.util.Collections;
|
124 | 128 | import java.util.HashMap;
|
|
134 | 138 | import static io.trino.metadata.GlobalFunctionCatalog.builtinFunctionName;
|
135 | 139 | import static io.trino.spi.type.BooleanType.BOOLEAN;
|
136 | 140 | import static io.trino.spi.type.DoubleType.DOUBLE;
|
| 141 | +import static io.trino.spi.type.RowType.anonymousRow; |
137 | 142 | import static io.trino.spi.type.TimeWithTimeZoneType.createTimeWithTimeZoneType;
|
138 | 143 | import static io.trino.spi.type.TimestampWithTimeZoneType.createTimestampWithTimeZoneType;
|
139 | 144 | import static io.trino.spi.type.TinyintType.TINYINT;
|
@@ -318,6 +323,7 @@ private io.trino.sql.ir.Expression translate(Expression expr, boolean isRoot)
|
318 | 323 | case FunctionCall expression -> translate(expression);
|
319 | 324 | case DereferenceExpression expression -> translate(expression);
|
320 | 325 | case Array expression -> translate(expression);
|
| 326 | + case MapLiteral expression -> translate(expression); |
321 | 327 | case CurrentCatalog expression -> translate(expression);
|
322 | 328 | case CurrentSchema expression -> translate(expression);
|
323 | 329 | case CurrentPath expression -> translate(expression);
|
@@ -687,6 +693,23 @@ private io.trino.sql.ir.Expression translate(DereferenceExpression expression)
|
687 | 693 | return new FieldReference(translateExpression(expression.getBase()), index);
|
688 | 694 | }
|
689 | 695 |
|
| 696 | + private io.trino.sql.ir.Expression translate(MapLiteral expression) |
| 697 | + { |
| 698 | + MapType mapType = (MapType) analysis.getType(expression); |
| 699 | + |
| 700 | + // convert entries to array(row(key, value)) |
| 701 | + List<io.trino.sql.ir.Expression> entries = new ArrayList<>(); |
| 702 | + for (EntryLiteral entry : expression.getEntries()) { |
| 703 | + entries.add(new io.trino.sql.ir.Row(ImmutableList.of(translateExpression(entry.key()), translateExpression(entry.value())))); |
| 704 | + } |
| 705 | + io.trino.sql.ir.Array array = new io.trino.sql.ir.Array(anonymousRow(mapType.getKeyType(), mapType.getValueType()), entries); |
| 706 | + |
| 707 | + return BuiltinFunctionCallBuilder.resolve(plannerContext.getMetadata()) |
| 708 | + .setName("map_from_entries") |
| 709 | + .addArgument(array.type(), array) |
| 710 | + .build(); |
| 711 | + } |
| 712 | + |
690 | 713 | private io.trino.sql.ir.Expression translate(Array expression)
|
691 | 714 | {
|
692 | 715 | List<io.trino.sql.ir.Expression> values = expression.getValues().stream()
|
|
0 commit comments