Пример #1
0
def infer_literal_type(value):
    import ibis.expr.rules as rules

    if value is None or value is null:
        return dt.null
    elif isinstance(value, bool):
        return dt.boolean
    elif isinstance(value, compat.integer_types):
        return rules.int_literal_class(value)
    elif isinstance(value, float):
        return dt.double
    elif isinstance(value, six.string_types):
        return dt.string
    elif isinstance(value, datetime.datetime):
        return dt.timestamp
    elif isinstance(value, datetime.date):
        return dt.date
    elif isinstance(value, datetime.time):
        return dt.time
    elif isinstance(value, list):
        if not value:
            return dt.Array(dt.any)
        return dt.Array(
            rules.highest_precedence_type(list(map(literal, value))))
    raise com.InputTypeError(value)
Пример #2
0
    def output_type(self):
        import ibis.expr.rules as rules

        value = self.value

        if isinstance(value, bool):
            return BooleanScalar
        elif isinstance(value, compat.integer_types):
            return rules.int_literal_class(value).scalar_type()
        elif isinstance(value, float):
            return DoubleScalar
        elif isinstance(value, six.string_types):
            return StringScalar
        elif isinstance(value, datetime.datetime):
            return TimestampScalar
        elif isinstance(value, datetime.date):
            return DateScalar
        elif isinstance(value, list):
            value_type = rules.highest_precedence_type(
                list(map(literal, value))
            )
            return lambda value, value_type=value_type: ArrayScalar(
                value, dt.Array(value_type)
            )

        raise com.InputTypeError(value)
Пример #3
0
    def output_type(self):
        import ibis.expr.rules as rules
        if isinstance(self.value, bool):
            klass = BooleanScalar
        elif isinstance(self.value, (int, long)):
            int_type = rules.int_literal_class(self.value)
            klass = int_type.scalar_type()
        elif isinstance(self.value, float):
            klass = DoubleScalar
        elif isinstance(self.value, six.string_types):
            klass = StringScalar
        elif isinstance(self.value, datetime.datetime):
            klass = TimestampScalar
        else:
            raise com.InputTypeError(self.value)

        return klass
Пример #4
0
    def output_type(self):
        import ibis.expr.rules as rules
        if isinstance(self.value, bool):
            klass = BooleanScalar
        elif isinstance(self.value, (int, long)):
            int_type = rules.int_literal_class(self.value)
            klass = int_type.scalar_type()
        elif isinstance(self.value, float):
            klass = DoubleScalar
        elif isinstance(self.value, six.string_types):
            klass = StringScalar
        elif isinstance(self.value, datetime.datetime):
            klass = TimestampScalar
        else:
            raise com.InputTypeError(self.value)

        return klass
Пример #5
0
def infer_literal_type(value):
    import ibis.expr.rules as rules

    if value is None or value is null:
        return dt.null
    elif isinstance(value, bool):
        return dt.boolean
    elif isinstance(value, compat.integer_types):
        return rules.int_literal_class(value)
    elif isinstance(value, float):
        return dt.double
    elif isinstance(value, six.string_types):
        return dt.string
    elif isinstance(value, datetime.timedelta):
        return dt.interval
    elif isinstance(value, datetime.datetime):
        return dt.timestamp
    elif isinstance(value, datetime.date):
        return dt.date
    elif isinstance(value, datetime.time):
        return dt.time
    elif isinstance(value, list):
        if not value:
            return dt.Array(dt.null)
        return dt.Array(
            rules.highest_precedence_type(list(map(literal, value))))
    elif isinstance(value, collections.OrderedDict):
        if not value:
            raise TypeError('Empty struct type not supported')
        return dt.Struct(
            list(value.keys()),
            [literal(element).type() for element in value.values()],
        )
    elif isinstance(value, dict):
        if not value:
            return dt.Map(dt.null, dt.null)
        return dt.Map(
            rules.highest_precedence_type(list(map(literal, value.keys()))),
            rules.highest_precedence_type(list(map(literal, value.values()))),
        )

    raise com.InputTypeError(value)