org.apache.spark.rdd.RDD.first()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(4.4k)|赞(0)|评价(0)|浏览(268)

本文整理了Java中org.apache.spark.rdd.RDD.first方法的一些代码示例,展示了RDD.first的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RDD.first方法的具体详情如下:
包路径:org.apache.spark.rdd.RDD
类名称:RDD
方法名:first

RDD.first介绍

暂无

代码示例

代码示例来源:origin: com.stratio.deep/deep-core

/**
 *
 * @param rdd
 * @param config
 * @param queryBuilder
 * @param <T>
 * @param <S>
 */
public static <T, S extends BaseConfig> void saveRDD(RDD<T> rdd, S config, UpdateQueryBuilder queryBuilder) {
  config.setRddId(rdd.id());
  config.setPartitionId(0);
  rdd.foreachPartition(new PrepareSaveFunction<>(queryBuilder, config, rdd.first()));
}

代码示例来源:origin: Stratio/deep-spark

/**
 *
 * @param rdd
 * @param config
 * @param queryBuilder
 * @param <T>
 * @param <S>
 */
public static <T, S extends BaseConfig> void saveRDD(RDD<T> rdd, S config, UpdateQueryBuilder queryBuilder) {
  config.setRddId(rdd.id());
  config.setPartitionId(0);
  rdd.foreachPartition(new PrepareSaveFunction<>(queryBuilder, config, rdd.first()));
}

代码示例来源:origin: com.stratio.deep/deep-cassandra

ClassTag$.MODULE$.<Tuple2<Cells, Cells>>apply(tuple.getClass()));
((CassandraDeepJobConfig) writeConfig).createOutputTableIfNeeded(mappedRDD.first());

代码示例来源:origin: com.stratio.deep/deep-cassandra

public static <W> void doCql3SaveToCassandra(RDD<W> rdd, ICassandraDeepJobConfig<W> writeConfig,
                       Function1<W, Tuple2<Cells, Cells>> transformer) {
  if (!writeConfig.getIsWriteConfig()) {
    throw new IllegalArgumentException("Provided configuration object is not suitable for writing");
  }
  Tuple2<Map<String, ByteBuffer>, Map<String, ByteBuffer>> tuple = new Tuple2<>(null, null);
  RDD<Tuple2<Cells, Cells>> mappedRDD = rdd.map(transformer,
      ClassTag$.MODULE$.<Tuple2<Cells, Cells>>apply(tuple.getClass()));
  ((CassandraDeepJobConfig) writeConfig).createOutputTableIfNeeded(mappedRDD.first());
  final int pageSize = writeConfig.getBatchSize();
  int offset = 0;
  List<Tuple2<Cells, Cells>> elements = Arrays.asList((Tuple2<Cells, Cells>[]) mappedRDD.collect());
  List<Tuple2<Cells, Cells>> split;
  do {
    split = elements.subList(pageSize * (offset++), Math.min(pageSize * offset, elements.size()));
    Batch batch = QueryBuilder.batch();
    for (Tuple2<Cells, Cells> t : split) {
      Tuple2<String[], Object[]> bindVars = Utils.prepareTuple4CqlDriver(t);
      Insert insert = QueryBuilder
          .insertInto(quote(writeConfig.getKeyspace()), quote(writeConfig.getTable()))
          .values(bindVars._1(), bindVars._2());
      batch.add(insert);
    }
    writeConfig.getSession().execute(batch);
  } while (!split.isEmpty() && split.size() == pageSize);
}

代码示例来源:origin: Stratio/deep-spark

/**
 * It tests if the extractor can read from the data store
 *
 * @param <W> the type parameter
 */
@Test(alwaysRun = true, groups = { "FunctionalTests" })
public <W> void testRead() {
  DeepSparkContext context = getDeepSparkContext();
  try {
    ExtractorConfig<W> inputConfigEntity = getReadExtractorConfig(databaseExtractorName, tableRead,
        inputEntity);
    RDD<W> inputRDDEntity = context.createRDD(inputConfigEntity);
    Assert.assertEquals(READ_COUNT_EXPECTED, inputRDDEntity.count());
    if (inputConfigEntity.getEntityClass().isAssignableFrom(Cells.class)) {
      Assert.assertEquals(((Cells) inputRDDEntity.first()).getCellByName("message").getCellValue(),
          READ_FIELD_EXPECTED);
      Assert.assertEquals(((Cells) inputRDDEntity.first()).getCellByName("id").getCellValue(),
          ID_MESSAGE_EXPECTED);
    } else {
      Assert.assertEquals(((MessageTestEntity) inputRDDEntity.first()).getMessage(), READ_FIELD_EXPECTED);
      Assert.assertEquals(((MessageTestEntity) inputRDDEntity.first()).getId(), ID_MESSAGE_EXPECTED);
    }
  } finally {
    context.stop();
  }
}

代码示例来源:origin: Stratio/deep-spark

Assert.assertEquals(((Cells) outputRDDEntity.first()).getCellByName("message").getCellValue(),
      READ_FIELD_EXPECTED);
} else {
  Assert.assertEquals(((MessageTestEntity) outputRDDEntity.first()).getMessage(), READ_FIELD_EXPECTED);

代码示例来源:origin: Stratio/deep-spark

Cells bookCells = (Cells) inputRDDEntity.first();
  assertNull(bookCells.getCellByName("cantos"));
} else {
  BookEntity bookEntity = (BookEntity) inputRDDEntity.first();
  Cells bookCells = (Cells) inputRDDEntity2.first();
  assertNotNull(bookCells.getCellByName("cantos").getCellValue());
} else {
  BookEntity bookEntity2 = (BookEntity) inputRDDEntity2.first();
  Cells bookCells = (Cells) inputRDDEntity3.first();
  assertNotNull(bookCells.getCellByName("cantos").getCellValue());
} else {
  BookEntity bookEntity = (BookEntity) inputRDDEntity3.first();

相关文章