当前位置: 首页>>代码示例>>Java>>正文


Java DataFrame.collect方法代码示例

本文整理汇总了Java中org.apache.spark.sql.DataFrame.collect方法的典型用法代码示例。如果您正苦于以下问题:Java DataFrame.collect方法的具体用法?Java DataFrame.collect怎么用?Java DataFrame.collect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.spark.sql.DataFrame的用法示例。


在下文中一共展示了DataFrame.collect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: CreateQuery

import org.apache.spark.sql.DataFrame; //导入方法依赖的package包/类
/**
 * Heuristic Naive SPARK implementation of Transitive closure.
 * 
 * @param oldTableName
 * @param newTableName
 * @param whereExpression
 * @param joinOnExpression
 * @param kleeneDepth1
 * @param kleeneDepth2
 * @param kleeneType
 * @param selectionPart
 */
public static void CreateQuery(String[] oldTableName, String newTableName, String whereExpression,
		ArrayList<String> joinOnExpression, int kleeneDepth1, int kleeneDepth2, String kleeneType,
		String[] selectionPart) {

	DataFrame resultFrame = null;
	SQLContext sqlContext = AppSpark.sqlContext;

	int numberOfLines = -1;

	KleeneFixed.CreateQuery(oldTableName, newTableName, whereExpression, joinOnExpression, 0, 3, kleeneType,
			selectionPart);

	String insertTmp = KleeneFixed.baseQuery;

	resultFrame = sqlContext.sql(insertTmp);
	resultFrame.registerTempTable("temp1");

	KleeneFixed.CreateQuery(oldTableName, newTableName, whereExpression, joinOnExpression, 4, -1, kleeneType,
			selectionPart);

	String minusOperation = "SELECT DISTINCT t.subject, t.predicate, t.object FROM (" + KleeneFixed.baseQuery
			+ ") t"
			+ " LEFT JOIN temp1 ON t.subject = temp1.subject AND t.predicate = temp1.predicate AND t.object = "
			+ " temp1.object WHERE temp1.predicate IS NULL ";

	baseQuery = baseQuery + minusOperation + "\n";

	resultFrame = sqlContext.sql(minusOperation);
	resultFrame.registerTempTable("temp2");

	String resultsChecking = "SELECT COUNT(*) AS count FROM temp2";

	resultFrame = sqlContext.sql(resultsChecking);

	Row[] results = resultFrame.collect();
	numberOfLines = (int) results[0].getLong(0);

	baseQuery = baseQuery + resultsChecking + "\n";

	System.out.println("# of new lines " + numberOfLines);

	if (numberOfLines != 0) {
		KleeneSemiNaiveSPARK.CreateQuery(oldTableName, newTableName, joinOnExpression, kleeneType, selectionPart,
				kleeneDepth1, "temp2");
	} else {
		resultFrame = sqlContext.sql("SELECT subject, predicate, object FROM temp1");
		QueryStruct.fillStructure(oldTableName, newTableName, baseQuery, "none", "none");
		ResultStruct.fillStructureSpark(resultFrame);
	}

}
 
开发者ID:martinpz,项目名称:TriAL-QL-Engine,代码行数:64,代码来源:KleeneHeuristicsSPARK.java


注:本文中的org.apache.spark.sql.DataFrame.collect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。