@@ -411,7 +411,7 @@ func (s *SchemaCheckPass) applyPhysicalFromExpression(currentSchema schema.Schem
411411 // TODO is this nessessery?
412412 if useCommonTable {
413413 if e .ColumnName == "timestamp" || e .ColumnName == "epoch_time" || e .ColumnName == `"epoch_time"` {
414- return model .NewColumnRef ("@timestamp" )
414+ return model .NewColumnRefWithTable ("@timestamp" , e . TableAlias )
415415 }
416416 }
417417 return e
@@ -602,7 +602,8 @@ func (s *SchemaCheckPass) applyFullTextField(indexSchema schema.Schema, query *m
602602 var expressions []model.Expr
603603
604604 for _ , field := range fullTextFields {
605- expressions = append (expressions , model .NewInfixExpr (model .NewColumnRef (field ), e .Op , e .Right ))
605+ colRef := model .NewColumnRefWithTable (field , col .TableAlias )
606+ expressions = append (expressions , model .NewInfixExpr (colRef , e .Op , e .Right ))
606607 }
607608
608609 res := model .Or (expressions )
@@ -644,7 +645,7 @@ func (s *SchemaCheckPass) applyTimestampField(indexSchema schema.Schema, query *
644645 timestampColumnName = *table.DiscoveredTimestampFieldName
645646 }
646647 */
647- var replacementExpr model. Expr
648+ var replacementName string
648649
649650 if timestampColumnName == "" {
650651 // no timestamp field found, replace with NULL if any
@@ -662,12 +663,12 @@ func (s *SchemaCheckPass) applyTimestampField(indexSchema schema.Schema, query *
662663
663664 // if the target column is not the canonical timestamp field, replace it
664665 if timestampColumnName != model .TimestampFieldName {
665- replacementExpr = model . NewColumnRef ( timestampColumnName )
666+ replacementName = timestampColumnName
666667 }
667668 }
668669
669670 // no replacement needed
670- if replacementExpr == nil {
671+ if replacementName == "" {
671672 return query , nil
672673 }
673674
@@ -676,7 +677,7 @@ func (s *SchemaCheckPass) applyTimestampField(indexSchema schema.Schema, query *
676677
677678 // full text field should be used only in where clause
678679 if e .ColumnName == model .TimestampFieldName {
679- return replacementExpr
680+ return model . NewColumnRefWithTable ( replacementName , e . TableAlias )
680681 }
681682 return e
682683 }
@@ -713,7 +714,7 @@ func (s *SchemaCheckPass) applyFieldEncoding(indexSchema schema.Schema, query *m
713714 }
714715
715716 if resolvedField , ok := indexSchema .ResolveField (e .ColumnName ); ok {
716- return model .NewColumnRef (resolvedField .InternalPropertyName .AsString ())
717+ return model .NewColumnRefWithTable (resolvedField .InternalPropertyName .AsString (), e . TableAlias )
717718 } else {
718719 if hasAttributesValuesColumn {
719720 return model .NewArrayAccess (model .NewColumnRef (clickhouse .AttributesValuesColumn ), model .NewLiteral (fmt .Sprintf ("'%s'" , e .ColumnName )))
0 commit comments