def cross_join(*args, **kwargs): """ Perform a cross join (cartesian product) amongst a list of tables, with optional set of prefixes to apply to overlapping column names Parameters ---------- positional args: tables to join prefixes keyword : prefixes for each table Not yet implemented Examples -------- >>> joined1 = ibis.cross_join(a, b, c, d, e) >>> joined2 = ibis.cross_join(a, b, c, prefixes=['a_', 'b_', 'c_'])) Returns ------- joined : TableExpr If prefixes not provided, the result schema is not yet materialized """ op = _ops.CrossJoin(*args, **kwargs) return TableExpr(op)
def cross_join( left: TableExpr, right: TableExpr, *rest: TableExpr, suffixes: tuple[str, str] = ("_x", "_y"), ) -> TableExpr: """Compute the cross join of a sequence of tables. Parameters ---------- left Left table right Right table rest Additional tables to cross join suffixes Left and right suffixes that will be used to rename overlapping columns. Returns ------- TableExpr Cross join of `left`, `right` and `rest` Examples -------- >>> import ibis >>> schemas = [(name, 'int64') for name in 'abcde'] >>> a, b, c, d, e = [ ... ibis.table([(name, type)], name=name) for name, type in schemas ... ] >>> joined1 = ibis.cross_join(a, b, c, d, e) >>> joined1 r0 := UnboundTable[e] e int64 r1 := UnboundTable[d] d int64 r2 := UnboundTable[c] c int64 r3 := UnboundTable[b] b int64 r4 := UnboundTable[a] a int64 r5 := CrossJoin[r3, r2] r6 := CrossJoin[r5, r1] r7 := CrossJoin[r6, r0] CrossJoin[r4, r7] """ from .. import operations as ops expr = ops.CrossJoin( left, functools.reduce(TableExpr.cross_join, rest, right), [], ).to_expr() return ops.relations._dedup_join_columns( expr, left=left, right=right, suffixes=suffixes, )
def cross_join(left, right, prefixes=None): """ """ op = _ops.CrossJoin(left, right) return TableExpr(op)