Class DruidTable

    • Field Detail

      • DEFAULT_TIMESTAMP_COLUMN

        public static final java.lang.String DEFAULT_TIMESTAMP_COLUMN
        See Also:
        Constant Field Values
      • DEFAULT_INTERVAL

        public static final org.joda.time.Interval DEFAULT_INTERVAL
      • dataSource

        final java.lang.String dataSource
      • metricFieldNames

        final com.google.common.collect.ImmutableSet<java.lang.String> metricFieldNames
      • intervals

        final com.google.common.collect.ImmutableList<org.joda.time.Interval> intervals
      • timestampFieldName

        final java.lang.String timestampFieldName
      • complexMetrics

        final com.google.common.collect.ImmutableMap<java.lang.String,​java.util.List<ComplexMetric>> complexMetrics
      • allFields

        final com.google.common.collect.ImmutableMap<java.lang.String,​SqlTypeName> allFields
    • Constructor Detail

      • DruidTable

        public DruidTable​(DruidSchema schema,
                          java.lang.String dataSource,
                          RelProtoDataType protoRowType,
                          java.util.Set<java.lang.String> metricFieldNames,
                          java.lang.String timestampFieldName,
                          java.util.List<org.joda.time.Interval> intervals,
                          java.util.Map<java.lang.String,​java.util.List<ComplexMetric>> complexMetrics,
                          java.util.Map<java.lang.String,​SqlTypeName> allFields)
        Creates a Druid table.
        Parameters:
        schema - Druid schema that contains this table
        dataSource - Druid data source name
        protoRowType - Field names and types
        metricFieldNames - Names of fields that are metrics
        intervals - Default interval if query does not constrain the time, or null
        timestampFieldName - Name of the column that contains the time
    • Method Detail

      • create

        static Table create​(DruidSchema druidSchema,
                            java.lang.String dataSourceName,
                            java.util.List<org.joda.time.Interval> intervals,
                            java.util.Map<java.lang.String,​SqlTypeName> fieldMap,
                            java.util.Set<java.lang.String> metricNameSet,
                            java.lang.String timestampColumnName,
                            DruidConnectionImpl connection,
                            java.util.Map<java.lang.String,​java.util.List<ComplexMetric>> complexMetrics)
        Creates a DruidTable by using the given DruidConnectionImpl to populate the other parameters. The parameters may be partially populated.
        Parameters:
        druidSchema - Druid schema
        dataSourceName - Data source name in Druid, also table name
        intervals - Intervals, or null to use default
        fieldMap - Partially populated map of fields (dimensions plus metrics)
        metricNameSet - Partially populated set of metric names
        timestampColumnName - Name of timestamp column, or null
        connection - Connection used to find column definitions; Must be non-null
        complexMetrics - List of complex metrics in Druid (thetaSketch, hyperUnique)
        Returns:
        A table
      • create

        static Table create​(DruidSchema druidSchema,
                            java.lang.String dataSourceName,
                            java.util.List<org.joda.time.Interval> intervals,
                            java.util.Map<java.lang.String,​SqlTypeName> fieldMap,
                            java.util.Set<java.lang.String> metricNameSet,
                            java.lang.String timestampColumnName,
                            java.util.Map<java.lang.String,​java.util.List<ComplexMetric>> complexMetrics)
        Creates a DruidTable by copying the given parameters.
        Parameters:
        druidSchema - Druid schema
        dataSourceName - Data source name in Druid, also table name
        intervals - Intervals, or null to use default
        fieldMap - Fully populated map of fields (dimensions plus metrics)
        metricNameSet - Fully populated set of metric names
        timestampColumnName - Name of timestamp column, or null
        complexMetrics - List of complex metrics in Druid (thetaSketch, hyperUnique)
        Returns:
        A table
      • resolveComplexMetric

        public ComplexMetric resolveComplexMetric​(java.lang.String alias,
                                                  AggregateCall call)
        Returns the appropriate ComplexMetric that is mapped from the given alias if it exists, and is used in the expected context with the given AggregateCall. Otherwise returns null.
      • isRolledUp

        public boolean isRolledUp​(java.lang.String column)
        Description copied from interface: Table
        Determines whether the given column has been rolled up.
        Specified by:
        isRolledUp in interface Table
        Overrides:
        isRolledUp in class AbstractTable
      • rolledUpColumnValidInsideAgg

        public boolean rolledUpColumnValidInsideAgg​(java.lang.String column,
                                                    SqlCall call,
                                                    SqlNode parent,
                                                    CalciteConnectionConfig config)
        Description copied from interface: Table
        Determines whether the given rolled up column can be used inside the given aggregate function. You can assume that isRolledUp(column) is true.
        Specified by:
        rolledUpColumnValidInsideAgg in interface Table
        Overrides:
        rolledUpColumnValidInsideAgg in class AbstractTable
        Parameters:
        column - The column name for which isRolledUp is true
        call - The aggregate call
        parent - Parent node of call in the SqlNode tree
        config - Config settings. May be null
        Returns:
        true iff the given aggregate call is valid
      • isValidParentKind

        private boolean isValidParentKind​(SqlNode node)
      • isCountDistinct

        private boolean isCountDistinct​(SqlCall call)
      • isSupportedPostAggOperation

        private boolean isSupportedPostAggOperation​(SqlKind kind)
      • getComplexMetricsFrom

        public java.util.List<ComplexMetric> getComplexMetricsFrom​(java.lang.String alias)
        Returns the list of ComplexMetric that match the given alias if it exists, otherwise returns an empty list, never null
      • isComplexMetric

        public boolean isComplexMetric​(java.lang.String alias)
        Returns true if and only if the given alias is a reference to a registered ComplexMetric
      • getRowType

        public RelDataType getRowType​(RelDataTypeFactory typeFactory)
        Description copied from interface: Table
        Returns this table's row type.

        This is a struct type whose fields describe the names and types of the columns in this table.

        The implementer must use the type factory provided. This ensures that the type is converted into a canonical form; other equal types in the same query will use the same object.

        Specified by:
        getRowType in interface Table
        Parameters:
        typeFactory - Type factory with which to create the type
        Returns:
        Row type
      • isMetric

        public boolean isMetric​(java.lang.String name)