def compile_array_slice(t, expr, scope, **kwargs): op = expr.op() start = op.start.op().value if op.start is not None else op.start stop = op.stop.op().value if op.stop is not None else op.stop spark_type = ibis_array_dtype_to_spark_dtype(op.arg.type()) @F.udf(spark_type) def array_slice(array): return array[start:stop] src_column = t.translate(op.arg, scope) return array_slice(src_column)
def compile_cast(t, expr, scope, **kwargs): op = expr.op() if isinstance(op.to, dtypes.Interval): if isinstance(op.arg.op(), ops.Literal): return interval(op.arg.op().value, op.to.unit) else: raise com.UnsupportedArgumentError( 'Casting to intervals is only supported for literals ' 'in the PySpark backend. {} not allowed.'.format(type(op.arg))) if isinstance(op.to, dtypes.Array): cast_type = ibis_array_dtype_to_spark_dtype(op.to) else: cast_type = ibis_dtype_to_spark_dtype(op.to) src_column = t.translate(op.arg, scope) return src_column.cast(cast_type)