gpt4 book ai didi

java - Pigunit给出错误类别未找到

转载 作者:行者123 更新时间:2023-12-03 06:02:10 26 4
gpt4 key购买 nike

我是Pig / Java设置的新手。我正在尝试测试apache门户上给出的样本单元测试。以下是代码

import java.io.IOException;

import org.apache.pig.pigunit.PigTest;
import org.junit.Test;
import org.junit.BeforeClass;
import org.apache.pig.test.Util;

import org.apache.pig.tools.parameters.ParseException;

public class PigQueriesTest {

@BeforeClass
public static void setUpOnce() throws Exception {
System.getProperties().setProperty("pigunit.exectype", Util.getLocalTestMode().toString());
}

@Test
public void testTop2Queries() throws ParseException, IOException {
String[] args = {
"n=2",
};

PigTest test = new PigTest("src/main/PigScripts/top_queries.pig", args);

String[] input = {
"yahoo",
"yahoo",
"yahoo",
"twitter",
"facebook",
"facebook",
"linkedin",
};

String[] output = {
"(yahoo1,5)",
"(facebook,2)",
};

test.assertOutput("data", input, "queries_limit", output);

}
}

错误是-
PigQueriesTest > testTop2Queries FAILED
java.lang.NoClassDefFoundError at PigQueriesTest.java:46
Caused by: java.lang.ClassNotFoundException at PigQueriesTest.java:46

即我在行上出错
 test.assertOutput("data", input, "queries_limit", output);

pig 脚本是
data =
LOAD 'input'
AS (query:CHARARRAY);

queries_group =
GROUP data
BY query;

queries_count =
FOREACH queries_group
GENERATE
group AS query,
COUNT(data) AS total;

queries_ordered =
ORDER queries_count
BY total DESC, query;

queries_limit =
LIMIT queries_ordered $n;

STORE queries_limit INTO 'output';

我在 Debug模式下运行了gradle。我正在追随错误
10:08:14.660 [DEBUG] [TestEventLogger] PigQueriesTest > testTop2Queries FAILED
10:08:14.660 [DEBUG] [TestEventLogger] java.lang.NoClassDefFoundError: org/apache/hadoop/mapred/JobConf
10:08:14.661 [DEBUG] [TestEventLogger] at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.LocalExecType.getExecutionEngine(LocalExecType.java:50)
10:08:14.661 [DEBUG] [TestEventLogger] at org.apache.pig.impl.PigContext.<init>(PigContext.java:270)
10:08:14.661 [DEBUG] [TestEventLogger] at org.apache.pig.PigServer.<init>(PigServer.java:206)
10:08:14.661 [DEBUG] [TestEventLogger] at org.apache.pig.PigServer.<init>(PigServer.java:202)
10:08:14.661 [DEBUG] [TestEventLogger] at org.apache.pig.pigunit.pig.PigServer.<init>(PigServer.java:39)
10:08:14.661 [DEBUG] [TestEventLogger] at org.apache.pig.pigunit.PigTest.getCluster(PigTest.java:144)
10:08:14.661 [DEBUG] [TestEventLogger] at org.apache.pig.pigunit.PigTest.registerScript(PigTest.java:170)
10:08:14.661 [DEBUG] [TestEventLogger] at org.apache.pig.pigunit.PigTest.assertOutput(PigTest.java:290)
10:08:14.661 [DEBUG] [TestEventLogger] at org.apache.pig.pigunit.PigTest.assertOutput(PigTest.java:285)
10:08:14.661 [DEBUG] [TestEventLogger] at PigQueriesTest.testTop2Queries(PigQueriesTest.java:46)
10:08:14.661 [DEBUG] [TestEventLogger] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
10:08:14.661 [DEBUG] [TestEventLogger] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
10:08:14.661 [DEBUG] [TestEventLogger] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

我在stackoverflow上遇到了一个问题,该问题要求停止扫描类文件以解决某些与gradle相关的问题。我的gradle构建文件是
// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin:'application'
apply plugin:'eclipse'
apply plugin: 'maven'

mainClassName = 'com.myudf.Main'

// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}


test {
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
}
}

//Necessary to stop gradle from scanning - GRADLE-1682 / GRADLE-3238
tasks.withType(Test) {
scanForTestClasses = false
include "**/*Test.class" // whatever Ant pattern matches your test class files
}


// In this section you declare the dependencies for your production and test code
dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'org.slf4j:slf4j-api:1.7.12'
compile group: 'org.apache.pig', name: 'pig', version: '0.14.0'

//https://repository.cloudera.com/artifactory/cloudera-repos/
compile group: "org.apache.hadoop", name: "hadoop-common", version: "2.6.0-cdh5.9.0"

// Dependencies for unit tests
compile group: 'org.apache.pig', name: 'pigunit', version: '0.14.0'
compile group: 'junit', name: 'junit', version: '4.12'
// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
testCompile 'junit:junit:4.12'
}

我在设置中缺少什么吗?

提前致谢
曼尼什

最佳答案

这是针对将来将要面对此问题的人们。经过一番谷歌搜索后,我能够解决此问题。我做了两件事来修复错误

1)首先我包括
// https://repository.cloudera.com/artifactory/cloudera-repos/


添加以上依赖后,我得到一个错误

16:08:57.029 [DEBUG] [TestEventLogger] PigQueriesTest > testTop2Queries FAILED
16:08:57.029 [DEBUG] [TestEventLogger] org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1066: Unable to open iterator for alias queries_limit

2)通过在Pig依赖项中添加分类器“h2”修复了以上错误
compile group: 'org.apache.pig', name: 'pig', version: '0.14.0', classifier: 'h2'

关于java - Pigunit给出错误类别未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41009604/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com