File tree Expand file tree Collapse file tree
packages/cubejs-query-orchestrator/src/orchestrator Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -436,8 +436,14 @@ export class QueryCache {
436436 query = QueryCache . replaceAll ( `${ tableName } ${ suffix } ` , usageTargetName , query ) ;
437437 }
438438 }
439- // Then replace base table name for any remaining references
440- return QueryCache . replaceAll ( tableName , targetTableName , query ) ;
439+ // Replace base table name only when there are no usage-specific replacements.
440+ // When usageTargetTableNames is present, all SQL references already use __usage_N suffixes
441+ // and the base replacement would incorrectly match inside already-replaced target names
442+ // (e.g. turning "preagg20200101_hash" into "preagg20200101_hash20200101_hash").
443+ if ( ! usageTargetTableNames || Object . keys ( usageTargetTableNames ) . length === 0 ) {
444+ return QueryCache . replaceAll ( tableName , targetTableName , query ) ;
445+ }
446+ return query ;
441447 } ,
442448 keyQuery
443449 ) ;
You can’t perform that action at this time.
0 commit comments