@@ -1030,83 +1030,82 @@ public List<Expression> bindSlotByScope(UnboundSlot unboundSlot, Scope scope) {
10301030
10311031 private List <? extends Expression > bindExpressionByCatalogDbTableColumn (
10321032 UnboundSlot unboundSlot , List <String > nameParts , Optional <Pair <Integer , Integer >> idxInSql , Scope scope ) {
1033- List <Slot > slots = addSqlIndexInfo ( bindSingleSlotByCatalog (
1034- nameParts .get (0 ), nameParts .get (1 ), nameParts .get (2 ), nameParts .get (3 ), scope ), idxInSql ) ;
1033+ List <Slot > slots = bindSingleSlotByCatalog (
1034+ nameParts .get (0 ), nameParts .get (1 ), nameParts .get (2 ), nameParts .get (3 ), scope );
10351035 if (slots .isEmpty ()) {
10361036 return bindExpressionByDbTableColumn (unboundSlot , nameParts , idxInSql , scope );
10371037 } else if (slots .size () > 1 ) {
1038- return slots ;
1038+ return addSqlIndexInfo ( slots , idxInSql ) ;
10391039 }
10401040 if (nameParts .size () == 4 ) {
1041- return slots ;
1041+ return addSqlIndexInfo ( slots , idxInSql ) ;
10421042 }
10431043
10441044 Optional <Expression > expression = bindNestedFields (
10451045 unboundSlot , slots .get (0 ), nameParts .subList (4 , nameParts .size ())
10461046 );
10471047 if (!expression .isPresent ()) {
1048- return slots ;
1048+ return addSqlIndexInfo ( slots , idxInSql ) ;
10491049 }
10501050 return ImmutableList .of (expression .get ());
10511051 }
10521052
10531053 private List <? extends Expression > bindExpressionByDbTableColumn (
10541054 UnboundSlot unboundSlot , List <String > nameParts , Optional <Pair <Integer , Integer >> idxInSql , Scope scope ) {
1055- List <Slot > slots = addSqlIndexInfo (
1056- bindSingleSlotByDb (nameParts .get (0 ), nameParts .get (1 ), nameParts .get (2 ), scope ), idxInSql );
1055+ List <Slot > slots = bindSingleSlotByDb (nameParts .get (0 ), nameParts .get (1 ), nameParts .get (2 ), scope );
10571056 if (slots .isEmpty ()) {
10581057 return bindExpressionByTableColumn (unboundSlot , nameParts , idxInSql , scope );
10591058 } else if (slots .size () > 1 ) {
1060- return slots ;
1059+ return addSqlIndexInfo ( slots , idxInSql ) ;
10611060 }
10621061 if (nameParts .size () == 3 ) {
1063- return slots ;
1062+ return addSqlIndexInfo ( slots , idxInSql ) ;
10641063 }
10651064
10661065 Optional <Expression > expression = bindNestedFields (
10671066 unboundSlot , slots .get (0 ), nameParts .subList (3 , nameParts .size ())
10681067 );
10691068 if (!expression .isPresent ()) {
1070- return slots ;
1069+ return addSqlIndexInfo ( slots , idxInSql ) ;
10711070 }
10721071 return ImmutableList .of (expression .get ());
10731072 }
10741073
10751074 private List <? extends Expression > bindExpressionByTableColumn (
10761075 UnboundSlot unboundSlot , List <String > nameParts , Optional <Pair <Integer , Integer >> idxInSql , Scope scope ) {
1077- List <Slot > slots = addSqlIndexInfo ( bindSingleSlotByTable (nameParts .get (0 ), nameParts .get (1 ), scope ), idxInSql );
1076+ List <Slot > slots = bindSingleSlotByTable (nameParts .get (0 ), nameParts .get (1 ), scope );
10781077 if (slots .isEmpty ()) {
10791078 return bindExpressionByColumn (unboundSlot , nameParts , idxInSql , scope );
10801079 } else if (slots .size () > 1 ) {
1081- return slots ;
1080+ return addSqlIndexInfo ( slots , idxInSql ) ;
10821081 }
10831082 if (nameParts .size () == 2 ) {
1084- return slots ;
1083+ return addSqlIndexInfo ( slots , idxInSql ) ;
10851084 }
10861085
10871086 Optional <Expression > expression = bindNestedFields (
10881087 unboundSlot , slots .get (0 ), nameParts .subList (2 , nameParts .size ())
10891088 );
10901089 if (!expression .isPresent ()) {
1091- return slots ;
1090+ return addSqlIndexInfo ( slots , idxInSql ) ;
10921091 }
10931092 return ImmutableList .of (expression .get ());
10941093 }
10951094
10961095 private List <? extends Expression > bindExpressionByColumn (
10971096 UnboundSlot unboundSlot , List <String > nameParts , Optional <Pair <Integer , Integer >> idxInSql , Scope scope ) {
1098- List <Slot > slots = addSqlIndexInfo ( bindSingleSlotByName (nameParts .get (0 ), scope ), idxInSql );
1097+ List <Slot > slots = bindSingleSlotByName (nameParts .get (0 ), scope );
10991098 if (slots .size () != 1 ) {
1100- return slots ;
1099+ return addSqlIndexInfo ( slots , idxInSql ) ;
11011100 }
11021101 if (nameParts .size () == 1 ) {
1103- return slots ;
1102+ return addSqlIndexInfo ( slots , idxInSql ) ;
11041103 }
11051104 Optional <Expression > expression = bindNestedFields (
11061105 unboundSlot , slots .get (0 ), nameParts .subList (1 , nameParts .size ())
11071106 );
11081107 if (!expression .isPresent ()) {
1109- return slots ;
1108+ return addSqlIndexInfo ( slots , idxInSql ) ;
11101109 }
11111110 return ImmutableList .of (expression .get ());
11121111 }
@@ -1134,9 +1133,26 @@ private Optional<Expression> bindNestedFields(UnboundSlot unboundSlot, Slot slot
11341133 }
11351134 throw new AnalysisException ("No such field '" + fieldName + "' in '" + lastFieldName + "'" );
11361135 }
1136+ addNestedFieldsSqlIndexInfo (unboundSlot , slot , fieldNames );
11371137 return Optional .of (new Alias (expression , unboundSlot .getName (), slot .getQualifier ()));
11381138 }
11391139
1140+ private void addNestedFieldsSqlIndexInfo (UnboundSlot unboundSlot , Slot slot , List <String > fieldNames ) {
1141+ Optional <Pair <Integer , Integer >> indexInSql = unboundSlot .getIndexInSqlString ();
1142+ if (!indexInSql .isPresent ()) {
1143+ return ;
1144+ }
1145+ ConnectContext connectContext = ConnectContext .get ();
1146+ if (connectContext == null || connectContext .getStatementContext () == null ) {
1147+ return ;
1148+ }
1149+ List <String > fullName = new ArrayList <>(slot .getQualifier ());
1150+ fullName .add (slot .getName ());
1151+ fullName .addAll (fieldNames );
1152+ connectContext .getStatementContext ().addIndexInSqlToString (indexInSql .get (),
1153+ Utils .qualifiedNameWithBackquote (fullName ));
1154+ }
1155+
11401156 public static boolean sameTableName (String boundSlot , String unboundSlot ) {
11411157 if (GlobalVariable .lowerCaseTableNames != 1 ) {
11421158 return boundSlot .equals (unboundSlot );
0 commit comments