Beispiel #1
0
    def get_timestamp_expression(self, time_grain):
        """Getting the time component of the query"""
        label = self.table.get_label(utils.DTTM_ALIAS)

        db = self.table.database
        pdf = self.python_date_format
        is_epoch = pdf in ('epoch_s', 'epoch_ms')
        if not self.expression and not time_grain and not is_epoch:
            return column(self.column_name, type_=DateTime).label(label)
        grain = None
        if time_grain:
            grain = db.grains_dict().get(time_grain)
            if not grain:
                raise NotImplementedError(
                    f'No grain spec for {time_grain} for database {db.database_name}'
                )
        expr = db.db_engine_spec.get_time_expr(
            self.expression or self.column_name, pdf, time_grain, grain)
        return literal_column(expr, type_=DateTime).label(label)
Beispiel #2
0
    def get_timestamp_expression(self, time_grain):
        """Getting the time component of the query"""
        label = utils.DTTM_ALIAS

        db = self.table.database
        pdf = self.python_date_format
        is_epoch = pdf in ('epoch_s', 'epoch_ms')
        if not self.expression and not time_grain and not is_epoch:
            sqla_col = column(self.column_name, type_=DateTime)
            return self.table.make_sqla_column_compatible(sqla_col, label)
        grain = None
        if time_grain:
            grain = db.grains_dict().get(time_grain)
            if not grain:
                raise NotImplementedError(
                    f'No grain spec for {time_grain} for database {db.database_name}')
        col = db.db_engine_spec.get_timestamp_column(self.expression, self.column_name)
        expr = db.db_engine_spec.get_time_expr(col, pdf, time_grain, grain)
        sqla_col = literal_column(expr, type_=DateTime)
        return self.table.make_sqla_column_compatible(sqla_col, label)