本文整理汇总了Java中org.apache.pig.parser.ParserException类的典型用法代码示例。如果您正苦于以下问题:Java ParserException类的具体用法?Java ParserException怎么用?Java ParserException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParserException类属于org.apache.pig.parser包,在下文中一共展示了ParserException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEscapedSchemaFromString
import org.apache.pig.parser.ParserException; //导入依赖的package包/类
public static Schema getEscapedSchemaFromString(String schemaStr) {
schemaStr = schemaStr.replaceAll("[\\r\\n]", "");
String[] fieldSchemaStrs = schemaStr.split(",");
StringBuilder escapedSchemaBuilder = new StringBuilder();
for (int i = 0; i < fieldSchemaStrs.length; i++) {
escapedSchemaBuilder.append(escapeFieldSchemaStr(fieldSchemaStrs[i]));
if (i != fieldSchemaStrs.length - 1)
escapedSchemaBuilder.append(",");
}
try {
return Utils.getSchemaFromString(escapedSchemaBuilder.toString());
} catch (ParserException pe) {
throw new IllegalArgumentException("Invalid schema format: " + pe.getMessage());
}
}
示例2: testForeachStarSchemaUnkown
import org.apache.pig.parser.ParserException; //导入依赖的package包/类
@Test
public void testForeachStarSchemaUnkown() throws IOException, ParserException{
PigServer pig = new PigServer(ExecType.LOCAL);
String query =
" l1 = load '" + INPUT_FILE + "' ;"
+ "f1 = foreach l1 generate * ;"
;
Util.registerMultiLineQuery(pig, query);
pig.explain("f1",System.out);
Iterator<Tuple> it = pig.openIterator("f1");
Tuple expectedResCharArray = (Tuple)Util.getPigConstant("('one','two')");
Tuple expectedRes = TupleFactory.getInstance().newTuple();
for(Object field : expectedResCharArray.getAll() ){
expectedRes.append(new DataByteArray(field.toString()));
}
assertTrue("has output", it.hasNext());
assertEquals(expectedRes, it.next());
}
示例3: testFilterCount3
import org.apache.pig.parser.ParserException; //导入依赖的package包/类
@Test
public void testFilterCount3() throws IOException, ParserException {
String query = "TESTDATA = load '"+TEST_FILTER_COUNT3_INPUT+"' using PigStorage() as (timestamp:chararray, testid:chararray, userid: chararray, sessionid:chararray, value:long, flag:int);" +
"TESTDATA_FILTERED = filter TESTDATA by (timestamp gte '1230800400000' and timestamp lt '1230804000000' and value != 0);" +
"TESTDATA_GROUP = group TESTDATA_FILTERED by testid;" +
"TESTDATA_AGG = foreach TESTDATA_GROUP {" +
" A = filter TESTDATA_FILTERED by (userid eq sessionid);" +
" C = distinct A.userid;" +
" generate group as testid, COUNT(TESTDATA_FILTERED) as counttestdata, COUNT(C) as distcount, SUM(TESTDATA_FILTERED.flag) as total_flags;" +
" }" +
"TESTDATA_AGG_1 = group TESTDATA_AGG ALL;" +
"TESTDATA_AGG_2 = foreach TESTDATA_AGG_1 generate COUNT(TESTDATA_AGG);" ;
pigServer.registerQuery(query);
Iterator<Tuple> it = pigServer.openIterator("TESTDATA_AGG_2");
int i = 0;
while(it.hasNext()) {
Tuple actual = it.next();
assertEquals(20l, actual.get(0));
i++;
}
assertEquals(1, i);
}
示例4: testUnionOnSchemaSameSchema
import org.apache.pig.parser.ParserException; //导入依赖的package包/类
/**
* Test UNION ONSCHEMA on two inputs with same schema
* @throws IOException
* @throws ParserException
*/
@Test
public void testUnionOnSchemaSameSchema() throws IOException, ParserException {
PigServer pig = new PigServer(ExecType.LOCAL);
String query =
" l1 = load '" + INP_FILE_2NUMS + "' as (i : int, j : int);"
+ "l2 = load '" + INP_FILE_2NUMS + "' as (i : int, j : int);"
+ "u = union onschema l1, l2;"
;
Util.registerMultiLineQuery(pig, query);
Schema expectedSch = Utils.getSchemaFromString("i: int, j: int");
Schema sch = pig.dumpSchema("u");
assertEquals("Checking expected schema",sch, expectedSch);
Iterator<Tuple> it = pig.openIterator("u");
List<Tuple> expectedRes =
Util.getTuplesFromConstantTupleStrings(
new String[] {
"(1,2)",
"(5,3)",
"(1,2)",
"(5,3)"
});
Util.checkQueryOutputsAfterSort(it, expectedRes);
}
示例5: testUnionOnSchemaCastOnByteArray
import org.apache.pig.parser.ParserException; //导入依赖的package包/类
/**
* Test UNION ONSCHEMA with cast from bytearray to another type
* @throws IOException
* @throws ParserException
*/
@Test
public void testUnionOnSchemaCastOnByteArray() throws IOException, ParserException {
PigServer pig = new PigServer(ExecType.LOCAL);
String query =
" l1 = load '" + INP_FILE_2NUMS + "' as (i, j);"
+ " f1 = foreach l1 generate (int)i, (int)j;"
+ "u = union onschema f1, l1;"
;
Util.registerMultiLineQuery(pig, query);
Iterator<Tuple> it = pig.openIterator("u");
List<Tuple> expectedRes =
Util.getTuplesFromConstantTupleStrings(
new String[] {
"(1,2)",
"(5,3)",
"(1,2)",
"(5,3)"
});
Util.checkQueryOutputsAfterSort(it, expectedRes);
}
示例6: testUnionOnSchemaScopedColumnNameNeg
import org.apache.pig.parser.ParserException; //导入依赖的package包/类
/**
* Test UNION ONSCHEMA where a common column has additional 'namespace' part
* in the column name in one of the inputs.
* Negative test case
* @throws IOException
* @throws ParserException
*/
@Test
public void testUnionOnSchemaScopedColumnNameNeg() throws IOException, ParserException {
String expectedErr = "Found more than one match: l1::i, l2::i";
String query_prefix =
" l1 = load '/tmp/fn' as (i : int, j : long); "
+ "l2 = load '/tmp/fn' as (i : int, j : long); "
+ "cg = cogroup l1 by i, l2 by i;"
+ "f = foreach cg generate flatten(l1), flatten(l2); "
+ "l3 = load '/tmp/fn2' as (i : int, j : long); "
;
String query = query_prefix + "u = union onschema f, l3; ";
checkSchemaEx(query, expectedErr);
// now try reversing the order of relation
query = query_prefix + "u = union onschema l3, f; ";
checkSchemaEx(query, expectedErr);
}
示例7: testUnionOnSchemaDiffNumType
import org.apache.pig.parser.ParserException; //导入依赖的package包/类
/**
* Test UNION ONSCHEMA on two inputs with same column names, but different
* numeric types - test type promotion
* @throws IOException
* @throws ParserException
*/
@Test
public void testUnionOnSchemaDiffNumType() throws IOException, ParserException {
PigServer pig = new PigServer(ExecType.LOCAL);
String query =
" l1 = load '" + INP_FILE_2NUMS + "' as (i : int, j : double);"
+ "l2 = load '" + INP_FILE_2NUMS + "' as (i : long, j : float);"
+ "u = union onschema l1, l2;"
;
Util.registerMultiLineQuery(pig, query);
Iterator<Tuple> it = pig.openIterator("u");
List<Tuple> expectedRes =
Util.getTuplesFromConstantTupleStrings(
new String[] {
"(1L,2.0)",
"(5L,3.0)",
"(1L,2.0)",
"(5L,3.0)"
});
Util.checkQueryOutputsAfterSort(it, expectedRes);
}
示例8: outputSchema
import org.apache.pig.parser.ParserException; //导入依赖的package包/类
@Override
public Schema outputSchema(Schema input) {
if (null != this.schemaFunction) {
try {
Tuple t = TupleFactory.getInstance().newTuple(1);
// Strip enclosing '{}' from schema
t.set(0, input.toString().replaceAll("^\\{", "").replaceAll("\\}$", ""));
return Utils.getSchemaFromString((String) this.schemaFunction.exec(t));
} catch (ParserException pe) {
throw new RuntimeException(pe);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
} else {
return this.schema;
}
}
示例9: JsFunction
import org.apache.pig.parser.ParserException; //导入依赖的package包/类
public JsFunction(String functionName) {
this.jsScriptEngine = JsScriptEngine.getInstance();
this.functionName = functionName;
Object outputSchemaObj = jsScriptEngine.jsEval(this.getClass().getName() + "(String)",
functionName + ".outputSchema");
//if no schema defined, fall back to bytearray
if (outputSchemaObj == null || outputSchemaObj instanceof Undefined) {
this.outputSchema = new Schema(new Schema.FieldSchema(null, DataType.BYTEARRAY));
}
else {
try {
this.outputSchema = Utils.getSchemaFromString(outputSchemaObj.toString());
}
catch (ParserException e) {
throw new IllegalArgumentException(functionName
+ ".outputSchema is not a valid schema: " + e.getMessage(), e);
}
}
}
示例10: testDereferenceTypeSet
import org.apache.pig.parser.ParserException; //导入依赖的package包/类
@Test
public void testDereferenceTypeSet() throws IOException, ParserException {
String query = "a = load 'a' as (i : int, j : int);"
+ " b = foreach a generate i, j/10.1 as jd;"
+ " c = group b by i;"
+ " d = foreach c generate MAX(b.jd) as mx;";
PigServer pig = new PigServer(ExecType.LOCAL);
Util.registerMultiLineQuery(pig, query);
Schema expectedSch =
Utils.getSchemaFromString("mx: double");
Schema sch = pig.dumpSchema("d");
assertEquals("Checking expected schema", expectedSch, sch);
}
示例11: testCastEmptyInnerSchema
import org.apache.pig.parser.ParserException; //导入依赖的package包/类
@Test
public void testCastEmptyInnerSchema() throws IOException, ParserException{
final String INP_FILE = "testCastEmptyInnerSchema.txt";
PrintWriter w = new PrintWriter(new FileWriter(INP_FILE));
w.println("(1,2)");
w.println("(2,3)");
w.close();
PigServer pigServer = new PigServer(LOCAL);
String query = "a = load '" + INP_FILE + "' as (t:tuple());" +
"b = foreach a generate (tuple(int, long))t;" +
"c = foreach b generate t.$0 + t.$1;";
Util.registerMultiLineQuery(pigServer, query);
List<Tuple> expectedRes =
Util.getTuplesFromConstantTupleStrings(
new String[] {
"(3L)",
"(5L)",
});
Iterator<Tuple> it = pigServer.openIterator("c");
Util.checkQueryOutputs(it, expectedRes);
}
示例12: read
import org.apache.pig.parser.ParserException; //导入依赖的package包/类
private static void read(PageReadStore columns, String pigSchemaString, String message) throws ParserException {
System.out.println(message);
MessageColumnIO columnIO = newColumnFactory(pigSchemaString);
TupleReadSupport tupleReadSupport = new TupleReadSupport();
Map<String, String> pigMetaData = pigMetaData(pigSchemaString);
MessageType schema = new PigSchemaConverter().convert(Utils.getSchemaFromString(pigSchemaString));
ReadContext init = tupleReadSupport.init(null, pigMetaData, schema);
RecordMaterializer<Tuple> recordConsumer = tupleReadSupport.prepareForRead(null, pigMetaData, schema, init);
RecordReader<Tuple> recordReader = columnIO.getRecordReader(columns, recordConsumer);
// TODO: put this back
// if (DEBUG) {
// recordConsumer = new RecordConsumerLoggingWrapper(recordConsumer);
// }
read(recordReader, 10000, pigSchemaString);
read(recordReader, 10000, pigSchemaString);
read(recordReader, 10000, pigSchemaString);
read(recordReader, 10000, pigSchemaString);
read(recordReader, 10000, pigSchemaString);
read(recordReader, 100000, pigSchemaString);
read(recordReader, 1000000, pigSchemaString);
System.out.println();
}
示例13: testBinStorageGetSchema
import org.apache.pig.parser.ParserException; //导入依赖的package包/类
@Test
public void testBinStorageGetSchema() throws IOException, ParserException {
String input[] = new String[] { "hello\t1\t10.1", "bye\t2\t20.2" };
String inputFileName = "testGetSchema-input.txt";
String outputFileName = "testGetSchema-output.txt";
try {
Util.createInputFile(pig.getPigContext(),
inputFileName, input);
String query = "a = load '" + inputFileName + "' as (c:chararray, " +
"i:int,d:double);store a into '" + outputFileName + "' using " +
"BinStorage();";
pig.setBatchOn();
Util.registerMultiLineQuery(pig, query);
pig.executeBatch();
ResourceSchema rs = new BinStorage().getSchema(outputFileName,
new Job(ConfigurationUtil.toConfiguration(pig.getPigContext().
getProperties())));
Schema expectedSchema = Utils.getSchemaFromString(
"c:chararray,i:int,d:double");
assertTrue("Checking binstorage getSchema output", Schema.equals(
expectedSchema, Schema.getPigSchema(rs), true, true));
} finally {
Util.deleteFile(pig.getPigContext(), inputFileName);
Util.deleteFile(pig.getPigContext(), outputFileName);
}
}
示例14: testProjectStarMulti
import org.apache.pig.parser.ParserException; //导入依赖的package包/类
/**
* Test projecting multiple *
* @throws IOException
* @throws ParseException
*/
@Test
public void testProjectStarMulti() throws IOException, ParserException {
PigServer pig = new PigServer(ExecType.LOCAL);
String query =
" l1 = load '" + INP_FILE_5FIELDS + "' as (a : int, b : int, c : int);"
+ "f = foreach l1 generate * as (aa, bb, cc), *;"
;
Util.registerMultiLineQuery(pig, query);
Schema expectedSch = Utils.getSchemaFromString(
"aa : int, bb : int, cc : int, a : int, b : int, c : int");
Schema sch = pig.dumpSchema("f");
assertEquals("Checking expected schema", expectedSch, sch);
List<Tuple> expectedRes =
Util.getTuplesFromConstantTupleStrings(
new String[] {
"(10,20,30,10,20,30)",
"(11,21,31,11,21,31)",
});
Iterator<Tuple> it = pig.openIterator("f");
Util.checkQueryOutputsAfterSort(it, expectedRes);
}
示例15: testNegativeForeachNOSchema
import org.apache.pig.parser.ParserException; //导入依赖的package包/类
/**
* -ve test cases
* @throws IOException
* @throws ParserException
*/
@Test
public void testNegativeForeachNOSchema() throws IOException, ParserException {
String query;
query =
" l1 = load '" + INP_FILE_5FIELDS + "';"
+ "f = foreach l1 generate $3 .. $1;"
;
Util.checkExceptionMessage(query, "f",
"start column appears after end column in range projection");
query =
" l1 = load '" + INP_FILE_5FIELDS + "' ;"
+ "f = foreach l1 generate a .. b;"
;
Util.checkExceptionMessage(query, "f",
"Invalid field projection. Projected field [a] does not exist.");
}