<commit_before>package frameless

import org.scalacheck.Prop
import org.scalacheck.Prop._

class JoinTests extends TypedDatasetSuite {
  test("ab.joinLeft(ac, ab.a, ac.a)") {
    def prop[A: TypedEncoder : Ordering, B, C](left: List[X2[A, B]], right: List[X2[A, C]])(
      implicit
      lefte: TypedEncoder[X2[A, B]],
      righte: TypedEncoder[X2[A, C]],
      joinede: TypedEncoder[(X2[A, B], Option[X2[A, C]])]
    ): Prop = {
      val leftDs = TypedDataset.create(left)
      val rightDs = TypedDataset.create(right)
      val joinedDs = leftDs
        .joinLeft(rightDs, leftDs.col('a), rightDs.col('a))
        .collect().run().toVector.sortBy(_._1.a)

      val rightKeys = right.map(_.a).toSet
      val joined = {
        for {
          ab <- left
          ac <- right if ac.a == ab.a
        } yield (ab, Some(ac))
      }.toVector ++ {
        for {
          ab <- left if !rightKeys.contains(ab.a)
        } yield (ab, None)
      }.toVector

      (joined.sortBy(_._1.a) ?= joinedDs) && (joinedDs.map(_._1).toSet ?= left.toSet)
    }

    check(forAll(prop[Int, Long, String] _))
  }

  test("ab.join(ac, ab.a, ac.a)") {
    def prop[A: TypedEncoder : Ordering, B, C](left: List[X2[A, B]], right: List[X2[A, C]])(
      implicit
      lefte: TypedEncoder[X2[A, B]],
      righte: TypedEncoder[X2[A, C]],
      joinede: TypedEncoder[(X2[A, B], X2[A, C])]
    ): Prop = {
      val leftDs = TypedDataset.create(left)
      val rightDs = TypedDataset.create(right)
      val joinedDs = leftDs
        .join(rightDs, leftDs.col('a), rightDs.col('a))
        .collect().run().toVector.sortBy(_._1.a)

      val joined = {
        for {
          ab <- left
          ac <- right if ac.a == ab.a
        } yield (ab, ac)
      }.toVector

      joined.sortBy(_._1.a) ?= joinedDs
    }

    check(forAll(prop[Int, Long, String] _))
  }
}<commit_msg>Fix JoinTests#{joinLeft, join}<commit_after>package frameless

import org.scalacheck.Prop
import org.scalacheck.Prop._

class JoinTests extends TypedDatasetSuite {
  import scala.math.Ordering.Implicits._

  test("ab.joinLeft(ac, ab.a, ac.a)") {
    def prop[A: TypedEncoder : Ordering, B: Ordering, C: Ordering](left: List[X2[A, B]], right: List[X2[A, C]])(
      implicit
      lefte: TypedEncoder[X2[A, B]],
      righte: TypedEncoder[X2[A, C]],
      joinede: TypedEncoder[(X2[A, B], Option[X2[A, C]])]
    ): Prop = {
      val leftDs = TypedDataset.create(left)
      val rightDs = TypedDataset.create(right)
      val joinedDs = leftDs
        .joinLeft(rightDs, leftDs.col('a), rightDs.col('a))
        .collect().run().toVector.sorted

      val rightKeys = right.map(_.a).toSet
      val joined = {
        for {
          ab <- left
          ac <- right if ac.a == ab.a
        } yield (ab, Some(ac))
      }.toVector ++ {
        for {
          ab <- left if !rightKeys.contains(ab.a)
        } yield (ab, None)
      }.toVector

      (joined.sorted ?= joinedDs) && (joinedDs.map(_._1).toSet ?= left.toSet)
    }

    check(forAll(prop[Int, Long, String] _))
  }

  test("ab.join(ac, ab.a, ac.a)") {
    def prop[A: TypedEncoder : Ordering, B: Ordering, C: Ordering](left: List[X2[A, B]], right: List[X2[A, C]])(
      implicit
      lefte: TypedEncoder[X2[A, B]],
      righte: TypedEncoder[X2[A, C]],
      joinede: TypedEncoder[(X2[A, B], X2[A, C])]
    ): Prop = {
      val leftDs = TypedDataset.create(left)
      val rightDs = TypedDataset.create(right)
      val joinedDs = leftDs
        .join(rightDs, leftDs.col('a), rightDs.col('a))
        .collect().run().toVector.sorted

      val joined = {
        for {
          ab <- left
          ac <- right if ac.a == ab.a
        } yield (ab, ac)
      }.toVector

      joined.sorted ?= joinedDs
    }

    check(forAll(prop[Int, Long, String] _))
  }
}
{'fraction_non_alphanumeric': 0.16521509633148587, 'fraction_numerical': 0.00791765637371338, 'mean_word_length': 2.3599290780141846, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1880856', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1412, 'n_words': 292}