@@ -23,7 +23,6 @@ import (
2323 "quesma/quesma/types"
2424 "quesma/schema"
2525 "quesma/stats"
26- "quesma/table_resolver"
2726 "quesma/telemetry"
2827 "quesma/util"
2928 quesma_api "quesma_v2/core"
5049 ingestFieldStatistics IngestFieldStatistics
5150 ingestFieldStatisticsLock sync.Mutex
5251 virtualTableStorage persistence.JSONDatabase
53- tableResolver table_resolver.TableResolver
5452 }
5553)
5654
@@ -442,63 +440,46 @@ func (lm *IngestProcessor2) Ingest(ctx context.Context, tableName string, jsonDa
442440 return lm .ProcessInsertQuery (ctx , tableName , jsonData , transformer , nameFormatter )
443441}
444442
443+ func (lm * IngestProcessor2 ) useCommonTable (tableName string ) bool {
444+ if tableConfig , ok := lm .cfg .IndexConfig [tableName ]; ok {
445+ return tableConfig .UseCommonTable
446+ }
447+ return false
448+ }
449+
445450func (lm * IngestProcessor2 ) ProcessInsertQuery (ctx context.Context , tableName string ,
446451 jsonData []types.JSON , transformer jsonprocessor.IngestTransformer ,
447452 tableFormatter TableColumNameFormatter ) error {
448453
449- decision := lm .tableResolver .Resolve (quesma_api .IngestPipeline , tableName )
450-
451- if decision .Err != nil {
452- return decision .Err
453- }
454-
455- if decision .IsEmpty { // TODO
456- return fmt .Errorf ("table %s not found" , tableName )
457- }
458-
459- if decision .IsClosed { // TODO
460- return fmt .Errorf ("table %s is closed" , tableName )
461- }
462-
463- for _ , connectorDecision := range decision .UseConnectors {
464-
465- var clickhouseDecision * quesma_api.ConnectorDecisionClickhouse
466-
467- var ok bool
468- if clickhouseDecision , ok = connectorDecision .(* quesma_api.ConnectorDecisionClickhouse ); ! ok {
469- continue
454+ if lm .useCommonTable (tableName ) {
455+ // we have clone the data, because we want to process it twice
456+ var clonedJsonData []types.JSON
457+ for _ , jsonValue := range jsonData {
458+ clonedJsonData = append (clonedJsonData , jsonValue .Clone ())
470459 }
471460
472- if clickhouseDecision .IsCommonTable { // TODO: TABLE_RESOLVER DECIDES WHETHER WE'RE DEALING WITH COMMON TABLE
473- // we have clone the data, because we want to process it twice
474- var clonedJsonData []types.JSON
475- for _ , jsonValue := range jsonData {
476- clonedJsonData = append (clonedJsonData , jsonValue .Clone ())
477- }
478-
479- err := lm .processInsertQueryInternal (ctx , tableName , clonedJsonData , transformer , tableFormatter , true )
480- if err != nil {
481- // we ignore an error here, because we want to process the data and don't lose it
482- logger .ErrorWithCtx (ctx ).Msgf ("error processing insert query - virtual table schema update: %v" , err )
483- }
484-
485- pipeline := jsonprocessor.IngestTransformerPipeline {}
486- pipeline = append (pipeline , & common_table.IngestAddIndexNameTransformer {IndexName : tableName })
487- pipeline = append (pipeline , transformer )
461+ err := lm .processInsertQueryInternal (ctx , tableName , clonedJsonData , transformer , tableFormatter , true )
462+ if err != nil {
463+ // we ignore an error here, because we want to process the data and don't lose it
464+ logger .ErrorWithCtx (ctx ).Msgf ("error processing insert query - virtual table schema update: %v" , err )
465+ }
488466
489- err = lm .processInsertQueryInternal (ctx , common_table .TableName , jsonData , pipeline , tableFormatter , false )
490- if err != nil {
491- return fmt .Errorf ("error processing insert query to a common table: %w" , err )
492- }
467+ pipeline := jsonprocessor.IngestTransformerPipeline {}
468+ pipeline = append (pipeline , & common_table.IngestAddIndexNameTransformer {IndexName : tableName })
469+ pipeline = append (pipeline , transformer )
493470
494- } else {
495- err := lm .processInsertQueryInternal (ctx , clickhouseDecision .ClickhouseTableName , jsonData , transformer , tableFormatter , false )
496- if err != nil {
497- return fmt .Errorf ("error processing insert query: %w" , err )
498- }
471+ err = lm .processInsertQueryInternal (ctx , common_table .TableName , jsonData , pipeline , tableFormatter , false )
472+ if err != nil {
473+ return fmt .Errorf ("error processing insert query to a common table: %w" , err )
499474 }
500475
476+ } else {
477+ err := lm .processInsertQueryInternal (ctx , tableName , jsonData , transformer , tableFormatter , false )
478+ if err != nil {
479+ return fmt .Errorf ("error processing insert query: %w" , err )
480+ }
501481 }
482+
502483 return nil
503484}
504485
@@ -667,9 +648,9 @@ func (ip *IngestProcessor2) Ping() error {
667648 return ip .chDb .Open ()
668649}
669650
670- func NewIngestProcessor2 (cfg * config.QuesmaConfiguration , chDb quesma_api.BackendConnector , phoneHomeAgent telemetry.PhoneHomeAgent , loader chLib.TableDiscovery , schemaRegistry schema.Registry , virtualTableStorage persistence.JSONDatabase , tableResolver table_resolver. TableResolver , esBackendConn backend_connectors.ElasticsearchBackendConnector ) * IngestProcessor2 {
651+ func NewIngestProcessor2 (cfg * config.QuesmaConfiguration , chDb quesma_api.BackendConnector , phoneHomeAgent telemetry.PhoneHomeAgent , loader chLib.TableDiscovery , schemaRegistry schema.Registry , virtualTableStorage persistence.JSONDatabase , esBackendConn backend_connectors.ElasticsearchBackendConnector ) * IngestProcessor2 {
671652 ctx , cancel := context .WithCancel (context .Background ())
672- return & IngestProcessor2 {ctx : ctx , cancel : cancel , chDb : chDb , tableDiscovery : loader , cfg : cfg , phoneHomeAgent : phoneHomeAgent , schemaRegistry : schemaRegistry , virtualTableStorage : virtualTableStorage , tableResolver : tableResolver , es : esBackendConn }
653+ return & IngestProcessor2 {ctx : ctx , cancel : cancel , chDb : chDb , tableDiscovery : loader , cfg : cfg , phoneHomeAgent : phoneHomeAgent , schemaRegistry : schemaRegistry , virtualTableStorage : virtualTableStorage , es : esBackendConn }
673654}
674655
675656// validateIngest validates the document against the table schema
0 commit comments