【问题标题】:Convert dataset into list row is taking much time将数据集转换为列表行需要很多时间
【发布时间】:2018-06-17 07:29:14
【问题描述】:

我正在计算 TFIDF,为此我需要将我的数据集转换为列表行。

我的数据集有 40,00,000 条记录,当我为我的数据集调用 collectAsList 函数时,它需要 20 多分钟才能完成。 我的 RAM 配置为 16gb。

基本上我需要处理单个行来计算该特定记录的 TFIDF。

请建议我是否有任何其他类型的函数可以将数据集转换为 spark 中的列表行。

即使我也尝试过 for 和 foreach 循环,但仍然需要时间。

下面是我的示例代码。

JavaSparkContext sc = new JavaSparkContext(new SparkConf().setAppName("SparkJdbcDs").setMaster("local[*]"));
SQLContext sqlContext = new SQLContext(sc);
SparkSession spark = SparkSession.builder().appName("connection example").getOrCreate();
Dataset<Row> tokenlist= sqlContext.read().format("com.databricks.spark.csv").option("header", "true").option("nullValue", "").load("D:\\AI_MATCHING\\exampleTFIDF.csv");
tokenlist= tokenlist.select("features");
tokenlist.show(false);
List<Row> tokenizedWordsList1 = tokenlist.collectAsList();

/*tokenlist.foreach((ForeachFunction<Row>) individaulRow -> {


    newtest.ItemIDSourceIndex=individaulRow.fieldIndex("ItemIDSource");
    newtest.upcSourceIndex=individaulRow.fieldIndex("upcSource");
    newtest.ManufacturerSourceIndex=individaulRow.fieldIndex("ManufacturerSource");
    newtest.ManufacturerPartNumberSourceIndex=individaulRow.fieldIndex("Manufacturer part NumberSource");
    newtest.PART_NUMBER_SOURCEIndex=individaulRow.fieldIndex("PART_NUMBER_SOURCE");
    newtest.productDescriptionSourceIndex=individaulRow.fieldIndex("productDescriptionSource");
    newtest.HASH_CODE_dummyIndex=individaulRow.fieldIndex("HASH_CODE_dummy");
    newtest.rowIdSourceIndex=individaulRow.fieldIndex("rowIdSource");
    newtest.rawFeaturesIndex=individaulRow.fieldIndex("rawfeatures                                                                                                                                                                                                                   ");
    newtest.featuresIndex=individaulRow.fieldIndex("features                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ");

    });*/

【问题讨论】:

  • Spark 已经实现了 TF-IDF,为什么不用呢? spark.apache.org/docs/2.2.0/ml-features.html#tf-idf
  • 在 TFIDF 计算之后,我需要获取单独的行并分配该值。
  • 你需要分配什么?使用提供的fit/transform 方法并设置输出列。
  • 基本上我需要找到 2 条记录之间的匹配,所以我需要分配 TFIDF 值。我需要列表形式的输出列而不是数据集形式

标签: apache-spark apache-spark-sql apache-spark-mllib


【解决方案1】:

A) Spark ML 库已经自行进行 TFIDF 计算,请尝试使用这些方法。

B) 如果你有大行(toList() 需要时间),尝试使用 SQL 方法。 如将数据集转换为表,并在一定条件下对其进行查询

【讨论】:

  • A) 我只使用 Spark ML 库计算 TFIDF。 B)我需要将数据集行转换为列表行并分配这些值以查找 2 条记录之间的匹配。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-01
  • 1970-01-01
相关资源
最近更新 更多