MCPcopy Index your code
hub / github.com/uber/aresdb / readSchema

Method readSchema

query/aql_compiler.go:468–542  ·  view source on GitHub ↗
(tableSchemaReader memCom.TableSchemaReader, shardOwner topology.ShardOwner)

Source from the content-addressed store, hash-verified

466}
467
468func (qc *AQLQueryContext) readSchema(tableSchemaReader memCom.TableSchemaReader, shardOwner topology.ShardOwner) {
469 qc.TableScanners = make([]*TableScanner, 1+len(qc.Query.Joins))
470 qc.TableIDByAlias = make(map[string]int)
471 qc.TableSchemaByName = make(map[string]*memCom.TableSchema)
472
473 tableSchemaReader.RLock()
474 defer tableSchemaReader.RUnlock()
475
476 // Main table.
477 schema := tableSchemaReader.GetSchemas()[qc.Query.Table]
478 if schema == nil {
479 qc.Error = utils.StackError(nil, "unknown main table %s", qc.Query.Table)
480 return
481 }
482 qc.TableSchemaByName[qc.Query.Table] = schema
483 schema.RLock()
484 qc.TableScanners[0] = &TableScanner{}
485 qc.TableScanners[0].Schema = schema
486
487 // use user query specified shards
488 // or all shards it owns when user did not specify
489 if len(qc.Query.Shards) == 0 {
490 qc.TableScanners[0].Shards = shardOwner.GetOwnedShards()
491 } else {
492 qc.TableScanners[0].Shards = qc.Query.Shards
493 }
494
495 qc.TableScanners[0].ColumnUsages = make(map[int]columnUsage)
496 if schema.Schema.IsFactTable {
497 // Archiving cutoff filter usage for fact table.
498 qc.TableScanners[0].ColumnUsages[0] = columnUsedByLiveBatches
499 }
500 qc.TableIDByAlias[qc.Query.Table] = 0
501
502 // Foreign tables.
503 for i, join := range qc.Query.Joins {
504 schema = tableSchemaReader.GetSchemas()[join.Table]
505 if schema == nil {
506 qc.Error = utils.StackError(nil, "unknown join table %s", join.Table)
507 return
508 }
509
510 if qc.TableSchemaByName[join.Table] == nil {
511 qc.TableSchemaByName[join.Table] = schema
512 // Prevent double locking.
513 schema.RLock()
514 }
515
516 qc.TableScanners[1+i] = &TableScanner{}
517 qc.TableScanners[1+i].Schema = schema
518 qc.TableScanners[1+i].ColumnUsages = make(map[int]columnUsage)
519 if schema.Schema.IsFactTable {
520 // we will only support fact to fact join within same shard
521 qc.TableScanners[1+i].Shards = qc.TableScanners[0].Shards
522 // Archiving cutoff filter usage for fact table.
523 qc.TableScanners[1+i].ColumnUsages[0] = columnUsedByLiveBatches
524 } else {
525 // for fact to dimension table join

Callers 2

CompileMethod · 0.95

Calls 5

StackErrorFunction · 0.92
RLockMethod · 0.65
RUnlockMethod · 0.65
GetSchemasMethod · 0.65
GetOwnedShardsMethod · 0.65

Tested by

no test coverage detected