use of org.apache.drill.common.exceptions.ChildErrorContext in project drill by apache.
the class KafkaRecordReader method open.
@Override
public boolean open(SchemaNegotiator negotiator) {
CustomErrorContext errorContext = new ChildErrorContext(negotiator.parentErrorContext()) {
@Override
public void addContext(UserException.Builder builder) {
super.addContext(builder);
builder.addContext("topic_name", subScanSpec.getTopicName());
}
};
negotiator.setErrorContext(errorContext);
messageReader = MessageReaderFactory.getMessageReader(readOptions.getMessageReader());
messageReader.init(negotiator, readOptions, plugin);
msgItr = new MessageIterator(messageReader.getConsumer(plugin), subScanSpec, readOptions.getPollTimeOut());
return true;
}
use of org.apache.drill.common.exceptions.ChildErrorContext in project drill by apache.
the class TextFormatPlugin method frameworkBuilder.
@Override
protected FileScanBuilder frameworkBuilder(OptionManager options, EasySubScan scan) throws ExecutionSetupException {
ColumnsScanBuilder builder = new ColumnsScanBuilder();
initScanBuilder(builder, scan);
TextParsingSettings settings = new TextParsingSettings(getConfig(), scan.getSchema());
builder.setReaderFactory(new ColumnsReaderFactory(settings, scan.getMaxRecords()));
// If this format has no headers, or wants to skip them,
// then we must use the columns column to hold the data.
builder.requireColumnsArray(!settings.isHeaderExtractionEnabled() && builder.providedSchema() == null);
// Text files handle nulls in an unusual way. Missing columns
// are set to required Varchar and filled with blanks. Yes, this
// means that the SQL statement or code cannot differentiate missing
// columns from empty columns, but that is how CSV and other text
// files have been defined within Drill.
builder.nullType(Types.required(MinorType.VARCHAR));
// The text readers use required Varchar columns to represent null columns.
builder.allowRequiredNullColumns(true);
// Provide custom error context
builder.errorContext(new ChildErrorContext(builder.errorContext()) {
@Override
public void addContext(UserException.Builder builder) {
super.addContext(builder);
builder.addContext("Extract headers:", Boolean.toString(getConfig().isHeaderExtractionEnabled()));
builder.addContext("Skip first line:", Boolean.toString(getConfig().isSkipFirstLine()));
}
});
return builder;
}
use of org.apache.drill.common.exceptions.ChildErrorContext in project drill by apache.
the class HttpXMLBatchReader method open.
@Override
public boolean open(SchemaNegotiator negotiator) {
HttpUrl url = buildUrl();
// Result set loader setup
String tempDirPath = negotiator.drillConfig().getString(ExecConstants.DRILL_TMP_DIR);
// Create user-friendly error context
CustomErrorContext errorContext = new ChildErrorContext(negotiator.parentErrorContext()) {
@Override
public void addContext(UserException.Builder builder) {
super.addContext(builder);
builder.addContext("URL", url.toString());
}
};
negotiator.setErrorContext(errorContext);
// Http client setup
SimpleHttp http = SimpleHttp.builder().scanDefn(subScan).url(url).tempDir(new File(tempDirPath)).paginator(paginator).proxyConfig(proxySettings(negotiator.drillConfig(), url)).errorContext(errorContext).build();
// Get the input stream
inStream = http.getInputStream();
// Initialize the XMLReader the reader
try {
xmlReader = new XMLReader(inStream, dataLevel, maxRecords);
resultLoader = negotiator.build();
if (implicitColumnsAreProjected()) {
implicitColumns = new ImplicitColumns(resultLoader.writer());
buildImplicitColumns();
populateImplicitFieldMap(http);
}
RowSetLoader rootRowWriter = resultLoader.writer();
xmlReader.open(rootRowWriter, errorContext);
xmlReader.implicitFields(implicitColumns);
} catch (XMLStreamException e) {
throw UserException.dataReadError(e).message("Error opening XML stream: " + e.getMessage()).addContext(errorContext).build(logger);
}
return true;
}
use of org.apache.drill.common.exceptions.ChildErrorContext in project drill by apache.
the class HttpScanBatchCreator method createBuilder.
private ScanFrameworkBuilder createBuilder(OptionManager options, HttpSubScan subScan) {
ScanFrameworkBuilder builder = new ScanFrameworkBuilder();
builder.projection(subScan.columns());
builder.setUserName(subScan.getUserName());
// Provide custom error context
builder.errorContext(new ChildErrorContext(builder.errorContext()) {
@Override
public void addContext(UserException.Builder builder) {
builder.addContext("Connection", subScan.tableSpec().connection());
builder.addContext("Plugin", subScan.tableSpec().pluginName());
}
});
// Reader
ReaderFactory readerFactory = new HttpReaderFactory(subScan);
builder.setReaderFactory(readerFactory);
builder.nullType(Types.optional(MinorType.VARCHAR));
return builder;
}
use of org.apache.drill.common.exceptions.ChildErrorContext in project drill by apache.
the class HttpBatchReader method open.
@Override
public boolean open(SchemaNegotiator negotiator) {
// Result set loader setup
String tempDirPath = negotiator.drillConfig().getString(ExecConstants.DRILL_TMP_DIR);
HttpUrl url = buildUrl();
logger.debug("Final URL: {}", url);
CustomErrorContext errorContext = new ChildErrorContext(negotiator.parentErrorContext()) {
@Override
public void addContext(UserException.Builder builder) {
super.addContext(builder);
builder.addContext("URL", url.toString());
}
};
negotiator.setErrorContext(errorContext);
// Http client setup
SimpleHttp http = SimpleHttp.builder().scanDefn(subScan).url(url).tempDir(new File(tempDirPath)).proxyConfig(proxySettings(negotiator.drillConfig(), url)).errorContext(errorContext).build();
// JSON loader setup
resultSetLoader = negotiator.build();
if (implicitColumnsAreProjected()) {
implicitColumns = new ImplicitColumns(resultSetLoader.writer());
buildImplicitColumns();
}
InputStream inStream = http.getInputStream();
populateImplicitFieldMap(http);
try {
JsonLoaderBuilder jsonBuilder = new JsonLoaderBuilder().implicitFields(implicitColumns).resultSetLoader(resultSetLoader).standardOptions(negotiator.queryOptions()).maxRows(maxRecords).dataPath(subScan.tableSpec().connectionConfig().dataPath()).errorContext(errorContext).fromStream(inStream);
if (subScan.tableSpec().connectionConfig().jsonOptions() != null) {
JsonLoaderOptions jsonOptions = subScan.tableSpec().connectionConfig().jsonOptions().getJsonOptions(negotiator.queryOptions());
jsonBuilder.options(jsonOptions);
} else {
jsonBuilder.standardOptions(negotiator.queryOptions());
}
jsonLoader = jsonBuilder.build();
} catch (Throwable t) {
// Paranoia: ensure stream is closed if anything goes wrong.
// After this, the JSON loader will close the stream.
AutoCloseables.closeSilently(inStream);
throw t;
}
return true;
}
Aggregations