processTimeFilter processes the time filter by matching it against the time column of the main fact table. The time filter will be identified as common filter if it does not match with the designated time column.
()
| 1608 | // column of the main fact table. The time filter will be identified as common |
| 1609 | // filter if it does not match with the designated time column. |
| 1610 | func (qc *AQLQueryContext) processTimeFilter() { |
| 1611 | from, to := qc.fromTime, qc.toTime |
| 1612 | |
| 1613 | // Match against time column of the main fact table. |
| 1614 | var timeColumnMatched bool |
| 1615 | |
| 1616 | tableColumnPair := strings.SplitN(qc.Query.TimeFilter.Column, ".", 2) |
| 1617 | if len(tableColumnPair) < 2 { |
| 1618 | qc.Query.TimeFilter.Column = tableColumnPair[0] |
| 1619 | } else { |
| 1620 | qc.Query.TimeFilter.Column = tableColumnPair[1] |
| 1621 | if tableColumnPair[0] != qc.Query.Table { |
| 1622 | qc.Error = utils.StackError(nil, "timeFilter only supports main table: %s, got: %s", qc.Query.Table, tableColumnPair[0]) |
| 1623 | return |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | if qc.TableScanners[0].Schema.Schema.IsFactTable { |
| 1628 | if from == nil { |
| 1629 | qc.Error = utils.StackError(nil, "'from' of time filter is missing") |
| 1630 | return |
| 1631 | } |
| 1632 | |
| 1633 | timeColumn := qc.TableScanners[0].Schema.Schema.Columns[0].Name |
| 1634 | if qc.Query.TimeFilter.Column == "" || qc.Query.TimeFilter.Column == timeColumn { |
| 1635 | timeColumnMatched = true |
| 1636 | qc.Query.TimeFilter.Column = timeColumn |
| 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | // TODO: resolve time filter column against foreign tables. |
| 1641 | timeColumnID := 0 |
| 1642 | found := false |
| 1643 | if qc.Query.TimeFilter.Column != "" { |
| 1644 | // Validate column existence and type. |
| 1645 | timeColumnID, found = qc.TableScanners[0].Schema.ColumnIDs[qc.Query.TimeFilter.Column] |
| 1646 | if !found { |
| 1647 | qc.Error = utils.StackError(nil, "unknown time filter column %s", |
| 1648 | qc.Query.TimeFilter.Column) |
| 1649 | return |
| 1650 | } |
| 1651 | timeColumnType := qc.TableScanners[0].Schema.ValueTypeByColumn[timeColumnID] |
| 1652 | if timeColumnType != memCom.Uint32 { |
| 1653 | qc.Error = utils.StackError(nil, |
| 1654 | "expect time filter column %s of type Uint32, but got %s", |
| 1655 | qc.Query.TimeFilter.Column, memCom.DataTypeName[timeColumnType]) |
| 1656 | return |
| 1657 | } |
| 1658 | } |
| 1659 | fromExpr, toExpr := common.CreateTimeFilterExpr(&expr.VarRef{ |
| 1660 | Val: qc.Query.TimeFilter.Column, |
| 1661 | ExprType: expr.Unsigned, |
| 1662 | TableID: 0, |
| 1663 | ColumnID: timeColumnID, |
| 1664 | DataType: memCom.Uint32, |
| 1665 | }, from, to) |
| 1666 | |
| 1667 | qc.TableScanners[0].ArchiveBatchIDEnd = int((utils.Now().Unix() + 86399) / 86400) |
no test coverage detected