aljoscha commented on a change in pull request #8685: [FLINK-12799][table] 
Improve expression based TableSchema extraction from DataStream/DataSet
URL: https://github.com/apache/flink/pull/8685#discussion_r292469662
 
 

 ##########
 File path: 
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/typeutils/FieldInfoUtils.java
 ##########
 @@ -381,105 +397,225 @@ public String getFieldName() {
                public int getIndex() {
                        return index;
                }
+
+               public DataType getType() {
+                       return type;
+               }
        }
 
-       private static class IndexedExprToFieldInfo extends 
ApiExpressionDefaultVisitor<Optional<FieldInfo>> {
+       private static class IndexedExprToFieldInfo extends 
ApiExpressionDefaultVisitor<FieldInfo> {
 
+               private final CompositeType<?> inputType;
                private final int index;
 
-               private IndexedExprToFieldInfo(int index) {
+               private IndexedExprToFieldInfo(CompositeType<?> inputType, int 
index) {
+                       this.inputType = inputType;
                        this.index = index;
                }
 
                @Override
-               public Optional<FieldInfo> 
visitUnresolvedReference(UnresolvedReferenceExpression unresolvedReference) {
+               public FieldInfo 
visitUnresolvedReference(UnresolvedReferenceExpression unresolvedReference) {
                        String fieldName = unresolvedReference.getName();
-                       return Optional.of(new FieldInfo(fieldName, index));
+                       return new FieldInfo(fieldName, index, 
fromLegacyInfoToDataType(getTypeAt(unresolvedReference)));
                }
 
                @Override
-               public Optional<FieldInfo> visitCall(CallExpression call) {
+               public FieldInfo visitCall(CallExpression call) {
                        if (call.getFunctionDefinition() == 
BuiltInFunctionDefinitions.AS) {
-                               List<Expression> children = call.getChildren();
-                               Expression origExpr = children.get(0);
-                               String newName = 
ExpressionUtils.extractValue(children.get(1), String.class)
-                                       .orElseThrow(() ->
-                                               new TableException("Alias 
expects string literal as new name. Got: " + children.get(1)));
-
-                               if (origExpr instanceof 
UnresolvedReferenceExpression) {
-                                       throw new TableException(
-                                               format("Alias '%s' is not 
allowed if other fields are referenced by position.", newName));
-                               } else if (isTimeAttribute(origExpr)) {
-                                       return Optional.empty();
-                               }
-                       } else if (isTimeAttribute(call)) {
-                               return Optional.empty();
+                               return visitAlias(call);
+                       } else if (isRowTimeExpression(call)) {
+                               validateRowtimeReplacesCompatibleType(call);
+                               return 
createTimeAttributeField(getChildAsReference(call), TimestampKind.ROWTIME, 
null);
+                       } else if (isProcTimeExpression(call)) {
+                               validateProcTimeAttributeAppended(call);
+                               return 
createTimeAttributeField(getChildAsReference(call), TimestampKind.PROCTIME, 
null);
                        }
 
                        return defaultMethod(call);
                }
 
+               private FieldInfo visitAlias(CallExpression call) {
+                       List<Expression> children = call.getChildren();
+                       String newName = 
ExpressionUtils.extractValue(children.get(1), String.class).orElseThrow(() ->
+                                       new ValidationException("Alias expects 
string literal as new name. Got: " + children.get(1)));
+
+                       Expression child = call.getChildren().get(0);
 
 Review comment:
   super nitpicky, but this could be `children.get(0)`, if I'm not mistaken, 
which could very well be.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to