test_class.file: modules/ml/src/test/java/org/apache/ignite/ml/dataset/impl/local/LocalDatasetBuilderTest.java
test_class.identifier: LocalDatasetBuilderTest
test_case.body: @Test
      public void testBuild() {
          Map<Integer, Integer> data = new HashMap<>();
          for (int i = 0; i < 100; i++)
              data.put(i, i);
  
          LocalDatasetBuilder<Integer, Integer> builder = new LocalDatasetBuilder<>(data, 10);
  
          LocalDataset<Serializable, TestPartitionData> dataset = buildDataset(builder);
  
          assertEquals(10, dataset.getCtx().size());
          assertEquals(10, dataset.getData().size());
  
          AtomicLong cnt = new AtomicLong();
  
          dataset.compute((partData, env) -> {
             cnt.incrementAndGet();
  
             int[] arr = partData.data;
  
             assertEquals(10, arr.length);
  
             for (int i = 0; i < 10; i++)
                 assertEquals(env.partition() * 10 + i, arr[i]);
          });
  
          assertEquals(10, cnt.intValue());
      }
test_case.class_method_signature: LocalDatasetBuilderTest.testBuild()
test_case.full_signature: @Test public void testBuild()
test_case.identifier: testBuild
test_case.invocations: put buildDataset assertEquals size getCtx assertEquals size getData compute incrementAndGet assertEquals assertEquals partition assertEquals intValue
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testBuild()
focal_class.declarator: upstreamMap
focal_class.modifier: private final
focal_class.original_string: private final Map<K, V> upstreamMap;
focal_class.type: Map<K, V>
focal_class.var_name: upstreamMap
focal_class.declarator: partitions
focal_class.modifier: private final
focal_class.original_string: private final int partitions;
focal_class.type: int
focal_class.var_name: partitions
focal_class.declarator: filter
focal_class.modifier: private final
focal_class.original_string: private final IgniteBiPredicate<K, V> filter;
focal_class.type: IgniteBiPredicate<K, V>
focal_class.var_name: filter
focal_class.declarator: upstreamTransformerBuilder
focal_class.modifier: private final
focal_class.original_string: private final UpstreamTransformerBuilder upstreamTransformerBuilder;
focal_class.type: UpstreamTransformerBuilder
focal_class.var_name: upstreamTransformerBuilder
focal_class.file: modules/ml/src/main/java/org/apache/ignite/ml/dataset/impl/local/LocalDatasetBuilder.java
focal_class.identifier: LocalDatasetBuilder
focal_class.interfaces: implements DatasetBuilder<K, V>
focal_class.class_method_signature: LocalDatasetBuilder.LocalDatasetBuilder(Map<K, V> upstreamMap, int partitions)
focal_class.full_signature: public  LocalDatasetBuilder(Map<K, V> upstreamMap, int partitions)
focal_class.identifier: LocalDatasetBuilder
focal_class.modifiers: public
focal_class.parameters: (Map<K, V> upstreamMap, int partitions)
focal_class.signature:  LocalDatasetBuilder(Map<K, V> upstreamMap, int partitions)
focal_class.class_method_signature: LocalDatasetBuilder.LocalDatasetBuilder(Map<K, V> upstreamMap,
          IgniteBiPredicate<K, V> filter,
          int partitions,
          UpstreamTransformerBuilder upstreamTransformerBuilder)
focal_class.full_signature: public  LocalDatasetBuilder(Map<K, V> upstreamMap,
          IgniteBiPredicate<K, V> filter,
          int partitions,
          UpstreamTransformerBuilder upstreamTransformerBuilder)
focal_class.identifier: LocalDatasetBuilder
focal_class.modifiers: public
focal_class.parameters: (Map<K, V> upstreamMap,
          IgniteBiPredicate<K, V> filter,
          int partitions,
          UpstreamTransformerBuilder upstreamTransformerBuilder)
focal_class.signature:  LocalDatasetBuilder(Map<K, V> upstreamMap,
          IgniteBiPredicate<K, V> filter,
          int partitions,
          UpstreamTransformerBuilder upstreamTransformerBuilder)
focal_class.class_method_signature: LocalDatasetBuilder.LocalDatasetBuilder(Map<K, V> upstreamMap,
          IgniteBiPredicate<K, V> filter,
          int partitions)
focal_class.full_signature: public  LocalDatasetBuilder(Map<K, V> upstreamMap,
          IgniteBiPredicate<K, V> filter,
          int partitions)
focal_class.identifier: LocalDatasetBuilder
focal_class.modifiers: public
focal_class.parameters: (Map<K, V> upstreamMap,
          IgniteBiPredicate<K, V> filter,
          int partitions)
focal_class.signature:  LocalDatasetBuilder(Map<K, V> upstreamMap,
          IgniteBiPredicate<K, V> filter,
          int partitions)
focal_class.class_method_signature: LocalDatasetBuilder.build(
          LearningEnvironmentBuilder envBuilder,
          PartitionContextBuilder<K, V, C> partCtxBuilder, PartitionDataBuilder<K, V, C, D> partDataBuilder,
          LearningEnvironment learningEnvironment)
focal_class.full_signature: @Override public LocalDataset<C, D> build(
          LearningEnvironmentBuilder envBuilder,
          PartitionContextBuilder<K, V, C> partCtxBuilder, PartitionDataBuilder<K, V, C, D> partDataBuilder,
          LearningEnvironment learningEnvironment)
focal_class.identifier: build
focal_class.modifiers: @Override public
focal_class.parameters: (
          LearningEnvironmentBuilder envBuilder,
          PartitionContextBuilder<K, V, C> partCtxBuilder, PartitionDataBuilder<K, V, C, D> partDataBuilder,
          LearningEnvironment learningEnvironment)
focal_class.return: LocalDataset<C, D>
focal_class.signature: LocalDataset<C, D> build(
          LearningEnvironmentBuilder envBuilder,
          PartitionContextBuilder<K, V, C> partCtxBuilder, PartitionDataBuilder<K, V, C, D> partDataBuilder,
          LearningEnvironment learningEnvironment)
focal_class.class_method_signature: LocalDatasetBuilder.withUpstreamTransformer(UpstreamTransformerBuilder builder)
focal_class.full_signature: @Override public DatasetBuilder<K, V> withUpstreamTransformer(UpstreamTransformerBuilder builder)
focal_class.identifier: withUpstreamTransformer
focal_class.modifiers: @Override public
focal_class.parameters: (UpstreamTransformerBuilder builder)
focal_class.return: DatasetBuilder<K, V>
focal_class.signature: DatasetBuilder<K, V> withUpstreamTransformer(UpstreamTransformerBuilder builder)
focal_class.class_method_signature: LocalDatasetBuilder.withFilter(IgniteBiPredicate<K, V> filterToAdd)
focal_class.full_signature: @Override public DatasetBuilder<K, V> withFilter(IgniteBiPredicate<K, V> filterToAdd)
focal_class.identifier: withFilter
focal_class.modifiers: @Override public
focal_class.parameters: (IgniteBiPredicate<K, V> filterToAdd)
focal_class.return: DatasetBuilder<K, V>
focal_class.signature: DatasetBuilder<K, V> withFilter(IgniteBiPredicate<K, V> filterToAdd)
focal_method.body: @Override public <C extends Serializable, D extends AutoCloseable> LocalDataset<C, D> build(
          LearningEnvironmentBuilder envBuilder,
          PartitionContextBuilder<K, V, C> partCtxBuilder, PartitionDataBuilder<K, V, C, D> partDataBuilder,
          LearningEnvironment learningEnvironment) {
  
          List<C> ctxList = new ArrayList<>();
          List<D> dataList = new ArrayList<>();
  
          List<UpstreamEntry<K, V>> entriesList = new ArrayList<>();
  
          upstreamMap
              .entrySet()
              .stream()
              .filter(en -> filter.apply(en.getKey(), en.getValue()))
              .map(en -> new UpstreamEntry<>(en.getKey(), en.getValue()))
              .forEach(entriesList::add);
  
          int partSize = Math.max(1, entriesList.size() / partitions);
  
          Iterator<UpstreamEntry<K, V>> firstKeysIter = entriesList.iterator();
          Iterator<UpstreamEntry<K, V>> secondKeysIter = entriesList.iterator();
          Iterator<UpstreamEntry<K, V>> thirdKeysIter = entriesList.iterator();
  
          int ptr = 0;
  
          List<LearningEnvironment> envs = IntStream.range(0, partitions).boxed().map(envBuilder::buildForWorker)
              .collect(Collectors.toList());
  
          for (int part = 0; part < partitions; part++) {
              int cntBeforeTransform =
                  part == partitions - 1 ? entriesList.size() - ptr : Math.min(partSize, entriesList.size() - ptr);
              LearningEnvironment env = envs.get(part);
              UpstreamTransformer transformer1 = upstreamTransformerBuilder.build(env);
              UpstreamTransformer transformer2 = Utils.copy(transformer1);
              UpstreamTransformer transformer3 = Utils.copy(transformer1);
  
              int cnt = (int)transformer1.transform(Utils.asStream(new IteratorWindow<>(thirdKeysIter, k -> k, cntBeforeTransform))).count();
  
              Iterator<UpstreamEntry> iter =
                  transformer2.transform(Utils.asStream(new IteratorWindow<>(firstKeysIter, k -> k, cntBeforeTransform)).map(x -> (UpstreamEntry)x)).iterator();
              Iterator<UpstreamEntry<K, V>> convertedBack = Utils.asStream(iter).map(x -> (UpstreamEntry<K, V>)x).iterator();
  
              C ctx = cntBeforeTransform > 0 ? partCtxBuilder.build(env, convertedBack, cnt) : null;
  
              Iterator<UpstreamEntry> iter1 = transformer3.transform(
                      Utils.asStream(new IteratorWindow<>(secondKeysIter, k -> k, cntBeforeTransform))).iterator();
  
              Iterator<UpstreamEntry<K, V>> convertedBack1 = Utils.asStream(iter1).map(x -> (UpstreamEntry<K, V>)x).iterator();
  
              D data = cntBeforeTransform > 0 ? partDataBuilder.build(
                  env,
                  convertedBack1,
                  cnt,
                  ctx
              ) : null;
  
              ctxList.add(ctx);
              dataList.add(data);
  
              ptr += cntBeforeTransform;
          }
  
          return new LocalDataset<>(envs, ctxList, dataList);
      }
focal_method.class_method_signature: LocalDatasetBuilder.build(
          LearningEnvironmentBuilder envBuilder,
          PartitionContextBuilder<K, V, C> partCtxBuilder, PartitionDataBuilder<K, V, C, D> partDataBuilder,
          LearningEnvironment learningEnvironment)
focal_method.full_signature: @Override public LocalDataset<C, D> build(
          LearningEnvironmentBuilder envBuilder,
          PartitionContextBuilder<K, V, C> partCtxBuilder, PartitionDataBuilder<K, V, C, D> partDataBuilder,
          LearningEnvironment learningEnvironment)
focal_method.identifier: build
focal_method.invocations: forEach map filter stream entrySet apply getKey getValue getKey getValue max size iterator iterator iterator collect map boxed range toList size min size get build copy copy count transform asStream iterator transform map asStream iterator map asStream build iterator transform asStream iterator map asStream build add add
focal_method.modifiers: @Override public
focal_method.parameters: (
          LearningEnvironmentBuilder envBuilder,
          PartitionContextBuilder<K, V, C> partCtxBuilder, PartitionDataBuilder<K, V, C, D> partDataBuilder,
          LearningEnvironment learningEnvironment)
focal_method.return: LocalDataset<C, D>
focal_method.signature: LocalDataset<C, D> build(
          LearningEnvironmentBuilder envBuilder,
          PartitionContextBuilder<K, V, C> partCtxBuilder, PartitionDataBuilder<K, V, C, D> partDataBuilder,
          LearningEnvironment learningEnvironment)