간단한 스칼라 애플리케이션 인 페이지 순위를 만들려고했지만 실행할 수 없습니다.
코드를 얻은 소스 : https://github.com/abbas-taher/pagerank-example-spark2.0-deep-dive
Intellij에서 com.scalaproj 패키지 인 새 scala 프로젝트를 만들고 소스의 코드를 scala 개체 인 SparkPageRank에 추가했습니다. 튜토리얼에서 언급했듯이 spark-2.1.0-bin-hadoop2.7에 대한 외부 jar도 추가했습니다.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// scalastyle:off println
package com.scalaproj
import org.apache.spark.sql.SparkSession
/**
* Computes the PageRank of URLs from an input file. Input file should
* be in format of:
* URL neighbor URL
* URL neighbor URL
* URL neighbor URL
* ...
* where URL and their neighbors are separated by space(s).
*
* This is an example implementation for learning how to use Spark. For more conventional use,
* please refer to org.apache.spark.graphx.lib.PageRank
*
* Example Usage:
* {{{
* bin/run-example SparkPageRank data/mllib/pagerank_data.txt 10
* }}}
*/
object SparkPageRank {
def showWarning() {
System.err.println(
"""WARN: This is a naive implementation of PageRank and is given as an example!
|Please use the PageRank implementation found in org.apache.spark.graphx.lib.PageRank
|for more conventional use.
""".stripMargin)
}
def main(args: Array[String]) {
if (args.length < 1) {
System.err.println("Usage: SparkPageRank <file> <iter>")
System.exit(1)
}
showWarning()
val spark = SparkSession
.builder
.appName("SparkPageRank")
.getOrCreate()
val iters = if (args.length > 1) args(1).toInt else 10
val lines = spark.read.textFile(args(0)).rdd
val links = lines.map{ s =>
val parts = s.split("\\s+")
(parts(0), parts(1))
}.distinct().groupByKey().cache()
var ranks = links.mapValues(v => 1.0)
for (i <- 1 to iters) {
val contribs = links.join(ranks).values.flatMap{ case (urls, rank) =>
val size = urls.size
urls.map(url => (url, rank / size))
}
ranks = contribs.reduceByKey(_ + _).mapValues(0.15 + 0.85 * _)
}
val output = ranks.collect()
output.foreach(tup => println(tup._1 + " has rank: " + tup._2 + "."))
spark.stop()
}
}
// scalastyle:on println
오류없이 프로젝트를 빌드했지만 실행하려고하면 다음과 같이 표시됩니다.
Error: Could not find or load main class com.scalaproj.SparkPageRank
이클립스에서도 같은 오류를 시도했습니다. 누군가 나에게 무엇을해야하는지 말해 줄 수 있습니까?
오류를 재현 할 수 있습니다. Intellij에서 SparkPageRank 개체를 포함하는 디렉터리를 Sources 루트로 표시하기 만하면됩니다. (디렉토리는 파란색이어야 함)
디렉토리를 마우스 오른쪽 버튼으로 클릭-> 디렉토리를 다음으로 표시-> 소스 루트
이것이 당신을 위해 일하기를 바랍니다!
======= 토론 후 업데이트 ======
이 솔루션이 작동하지 않기 때문에 메이븐 프로젝트를 만들고 스파크 및 스칼라 종속성을 추가해야합니다. github 링크에서 코드가 pom.xml 또는 build.sbt없이 작동하는지 확실하지 않습니다.
======= 11/13 업데이트 =======
build.sbt로 작업 한 코드
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다