presto-main/src/main/java/io/prestosql/sql/planner/DesugarRowSubscriptRewriter.java/DesugarRowSubscriptRewriter/rewriteSubscriptExpression
class DesugarRowSubscriptRewriter:        @Override
        public Expression rewriteSubscriptExpression(SubscriptExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter)
        {
            Expression base = node.getBase();
            Expression index = node.getIndex();

            Expression result = node;

            Type type = getType(base);
            if (type instanceof RowType) {
                RowType rowType = (RowType) type;
                int position = toIntExact(((LongLiteral) index).getValue() - 1);

                Optional<String> fieldName = rowType.getFields().get(position).getName();

                // Do not cast if Row fields are named
                if (fieldName.isPresent()) {
                    result = new DereferenceExpression(base, new Identifier(fieldName.get(), true));
                }
                else {
                    // Cast to Row with named fields
                    ImmutableList.Builder<RowType.Field> namedFields = new ImmutableList.Builder<>();
                    for (int i = 0; i < rowType.getFields().size(); i++) {
                        namedFields.add(new RowType.Field(Optional.of("f" + i), rowType.getTypeParameters().get(i)));
                    }
                    RowType namedRowType = RowType.from(namedFields.build());
                    Cast cast = new Cast(base, toSqlType(namedRowType));
                    result = new DereferenceExpression(cast, new Identifier("f" + position));
                }
            }

            return treeRewriter.defaultRewrite(result, context);
        }