join method

LazyFrame join(
  1. LazyFrame other, {
  2. required Iterable<Expr> leftOn,
  3. required Iterable<Expr> rightOn,
  4. String how = 'inner',
  5. String suffix = '_right',
  6. bool coalesce = false,
})

Implementation

LazyFrame join(
  LazyFrame other, {
  required Iterable<Expr> leftOn,
  required Iterable<Expr> rightOn,
  String how = 'inner',
  String suffix = '_right',
  bool coalesce = false,
}) {
  _runtime._requireLazy(other);
  final left = List<Expr>.unmodifiable(leftOn);
  final right = List<Expr>.unmodifiable(rightOn);
  for (final value in [...left, ...right]) {
    _runtime._requireExpr(value);
  }
  const modes = {
    'inner',
    'left',
    'right',
    'full',
    'outer',
    'semi',
    'anti',
    'cross',
  };
  if (!modes.contains(how)) {
    throw ArgumentError.value(how, 'how', 'unsupported join mode');
  }
  if (how == 'cross' && (left.isNotEmpty || right.isNotEmpty)) {
    throw ArgumentError('Cross joins must not specify keys');
  }
  if (how != 'cross' && (left.isEmpty || left.length != right.length)) {
    throw ArgumentError(
      'leftOn and rightOn must have equal, non-zero lengths',
    );
  }
  if (coalesce && {'semi', 'anti', 'cross'}.contains(how)) {
    throw ArgumentError.value(
      coalesce,
      'coalesce',
      'is invalid for $how joins',
    );
  }
  final resources = <_HandleOwner>[
    _owner,
    other._owner,
    ...left.map((x) => x._owner),
    ...right.map((x) => x._owner),
  ];
  final leases = _leaseAll(resources);
  try {
    final keyStart = 2;
    final rightStart = keyStart + left.length;
    return _runtime._adoptLazy(
      _runtime._client.invokeSync('lazyJoin', {
        'left': leases[0].handle.toString(),
        'right': leases[1].handle.toString(),
        'leftOn': leases
            .sublist(keyStart, rightStart)
            .map((x) => x.handle.toString())
            .toList(),
        'rightOn': leases
            .sublist(rightStart)
            .map((x) => x.handle.toString())
            .toList(),
        'how': how,
        'suffix': suffix,
        'coalesce': coalesce,
      }),
    );
  } finally {
    _releaseAll(leases);
  }
}