Search in sources :

Example 1 with XMLReader

use of org.apache.drill.exec.store.xml.XMLReader 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;
}
Also used : SimpleHttp(org.apache.drill.exec.store.http.util.SimpleHttp) XMLStreamException(javax.xml.stream.XMLStreamException) ChildErrorContext(org.apache.drill.common.exceptions.ChildErrorContext) RowSetLoader(org.apache.drill.exec.physical.resultSet.RowSetLoader) File(java.io.File) HttpUrl(okhttp3.HttpUrl) XMLReader(org.apache.drill.exec.store.xml.XMLReader) ImplicitColumns(org.apache.drill.exec.store.ImplicitColumnUtils.ImplicitColumns) CustomErrorContext(org.apache.drill.common.exceptions.CustomErrorContext)

Aggregations

File (java.io.File)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 HttpUrl (okhttp3.HttpUrl)1 ChildErrorContext (org.apache.drill.common.exceptions.ChildErrorContext)1 CustomErrorContext (org.apache.drill.common.exceptions.CustomErrorContext)1 RowSetLoader (org.apache.drill.exec.physical.resultSet.RowSetLoader)1 ImplicitColumns (org.apache.drill.exec.store.ImplicitColumnUtils.ImplicitColumns)1 SimpleHttp (org.apache.drill.exec.store.http.util.SimpleHttp)1 XMLReader (org.apache.drill.exec.store.xml.XMLReader)1