use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project drill by apache.
the class BaseJsonProcessor method processJSONException.
/*
* DRILL - 4653 This method processes JSON tokens until it reaches end of the
* current line when it processes start of a new JSON line { - return
* PROC_SUCCEED when it sees EOF the stream - there may not be a closing }
*/
protected JsonExceptionProcessingState processJSONException() throws IOException {
while (!parser.isClosed()) {
try {
JsonToken currentToken = parser.nextToken();
if (currentToken == JsonToken.START_OBJECT && (lastSeenJsonToken == JsonToken.END_OBJECT || lastSeenJsonToken == null)) {
lastSeenJsonToken = currentToken;
break;
}
lastSeenJsonToken = currentToken;
} catch (com.fasterxml.jackson.core.JsonParseException ex1) {
if (ex1.getOriginalMessage().startsWith(JACKSON_PARSER_EOF_FILE_MSG)) {
return JsonExceptionProcessingState.END_OF_STREAM;
}
continue;
}
}
return JsonExceptionProcessingState.PROC_SUCCEED;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project drill by apache.
the class BaseJsonReader method write.
@Override
public ReadState write(ComplexWriter writer) throws IOException {
try {
JsonToken t = lastSeenJsonToken;
if (t == null || t == JsonToken.END_OBJECT) {
t = parser.nextToken();
}
while (!parser.hasCurrentToken() && !parser.isClosed()) {
t = parser.nextToken();
}
lastSeenJsonToken = null;
if (parser.isClosed()) {
return ReadState.END_OF_STREAM;
}
ReadState readState = writeToVector(writer, t);
switch(readState) {
case END_OF_STREAM:
case WRITE_SUCCEED:
return readState;
default:
throw getExceptionWithContext(UserException.dataReadError(), null).message("Failure while reading JSON. (Got an invalid read state %s )", readState.toString()).build(logger);
}
} catch (com.fasterxml.jackson.core.JsonParseException ex) {
if (ignoreJSONParseError()) {
if (processJSONException() == JsonExceptionProcessingState.END_OF_STREAM) {
return ReadState.JSON_RECORD_PARSE_EOF_ERROR;
} else {
return ReadState.JSON_RECORD_PARSE_ERROR;
}
} else {
throw ex;
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project drill by apache.
the class MongoBinaryValueParser method parseV1Format.
// Parse field: { ($binary | $type) ^ ...
private void parseV1Format(String fieldName, TokenIterator tokenizer) {
boolean sawData = false;
for (; ; ) {
// key: ^value
JsonToken token = requireScalar(tokenizer);
if (fieldName.equals(ExtendedTypeNames.BINARY)) {
if (sawData) {
throw syntaxError();
}
sawData = true;
listener.onValue(token, tokenizer);
}
// key: value ^(} | key ...)
token = tokenizer.requireNext();
if (token == JsonToken.END_OBJECT) {
break;
}
if (token != JsonToken.FIELD_NAME) {
throw syntaxError();
}
fieldName = tokenizer.textValue();
switch(fieldName) {
case ExtendedTypeNames.BINARY:
case ExtendedTypeNames.BINARY_TYPE:
break;
default:
throw syntaxError();
}
}
if (!sawData) {
throw syntaxError();
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project drill by apache.
the class MongoBinaryValueParser method parse.
@Override
public void parse(TokenIterator tokenizer) {
// Null: assume the value is null
// (Extension to extended types)
JsonToken token = tokenizer.requireNext();
if (token == JsonToken.VALUE_NULL) {
listener.onValue(token, tokenizer);
return;
}
// This is a harmless extension to the standard.
if (token.isScalarValue()) {
listener.onValue(token, tokenizer);
return;
}
// Must be an object
requireToken(token, JsonToken.START_OBJECT);
// { ^($binary | $type)
requireToken(tokenizer, JsonToken.FIELD_NAME);
String fieldName = tokenizer.textValue();
if (fieldName.equals(ExtendedTypeNames.BINARY_TYPE)) {
// { $type ^
parseV1Format(fieldName, tokenizer);
} else if (!fieldName.equals(ExtendedTypeNames.BINARY)) {
throw syntaxError();
} else if (tokenizer.peek() == JsonToken.START_OBJECT) {
// { $binary: ^{
parseV2Format(tokenizer);
} else {
// { $binary: ^value
parseV1Format(fieldName, tokenizer);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project drill by apache.
the class MongoDateValueParser method parse.
@Override
public void parse(TokenIterator tokenizer) {
// Null: assume the value is null
// (Extension to extended types)
JsonToken token = tokenizer.requireNext();
if (token == JsonToken.VALUE_NULL) {
listener.onValue(token, tokenizer);
return;
}
// (Extension to extended types: allow strings.)
if (token.isScalarValue()) {
listener.onValue(token, tokenizer);
return;
}
// Must be an object
requireToken(token, JsonToken.START_OBJECT);
// Field name must be correct
requireField(tokenizer, ExtendedTypeNames.DATE);
// If value is an object, assume V2 canonical format.
token = tokenizer.requireNext();
if (token == JsonToken.START_OBJECT) {
tokenizer.unget(token);
parseExtended(tokenizer, ExtendedTypeNames.LONG);
} else {
// Otherwise, Value must be a scalar
tokenizer.unget(token);
listener.onValue(requireScalar(tokenizer), tokenizer);
}
// Must be no other fields
requireToken(tokenizer, JsonToken.END_OBJECT);
}
Aggregations