public class SchemaNegotiatorImpl extends Object implements SchemaNegotiator
Handles both early- and late-schema readers. Early-schema readers provide a table schema, late-schema readers do not.
If the reader (or, later, the scanner) has a SELECT list, then that select list is pushed down into the result set loader created for the reader.
Also handles parsing out various column types, filling in null columns and (via the vector cache), minimizing changes across readers. In the worst case, a reader might have a column "c" in one file, might skip "c" in the second file, and "c" may appear again in a third file. This negotiator, along with the scan projection and vector cache, "smoothes out" schema changes by preserving the vector for "c" across all three files. In the first and third files "c" is a vector written by the reader, in the second, it is a null column filled in by the scan projector (assuming, of course, that "c" is nullable or an array.)
Pushes limits into the result set loader. The caller must
either check the return value from {#code startBatch()}, or
call atLimit()
after harvest()
to detect when the scan
has reached the limit. Treat the limit condition the same as EOF.
Modifier and Type | Field and Description |
---|---|
protected CustomErrorContext |
baseErrorContext |
protected int |
batchSize |
protected boolean |
isSchemaComplete |
protected CustomErrorContext |
readerErrorContext |
protected ReaderLifecycle |
readerLifecycle |
protected TupleMetadata |
readerSchema |
Constructor and Description |
---|
SchemaNegotiatorImpl(ReaderLifecycle readerLifecycle) |
Modifier and Type | Method and Description |
---|---|
void |
batchSize(int maxRecordsPerBatch)
Set the preferred batch size (which may be overridden by the
result set loader in order to limit vector or batch size.)
|
ResultSetLoader |
build()
Callback from the schema negotiator to build the schema from information from
both the table and scan operator.
|
OperatorContext |
context() |
CustomErrorContext |
errorContext()
Returns the error context to use for this reader: either the
parent or the reader-specific context set in
SchemaNegotiator.setErrorContext(CustomErrorContext) . |
StaticBatchBuilder |
implicitColumnsLoader() |
TupleMetadata |
inputSchema()
Returns the reader input schema: the schema which describes the
set of columns this reader should produce.
|
boolean |
isProjectionEmpty()
Report whether the projection list is empty, as occurs in two
cases:
SELECT COUNT(*) ... -- empty project.
SELECT a, b FROM table(c d) -- disjoint project.
|
boolean |
isSchemaComplete() |
ManagedReader |
newReader(ReaderFactory<?> readerFactory) |
protected void |
onEndBatch() |
CustomErrorContext |
parentErrorContext()
The context to use as a parent when creating a custom context.
|
ProjectedColumn |
projectionFor(String colName) |
TupleMetadata |
providedSchema()
Returns the provided schema, if defined.
|
void |
schemaIsComplete(boolean isComplete) |
void |
setErrorContext(CustomErrorContext errorContext)
Specify an advanced error context which allows the reader to
fill in custom context values.
|
void |
tableSchema(TupleMetadata schema) |
void |
tableSchema(TupleMetadata schema,
boolean isComplete)
Specify the table schema if this is an early-schema reader.
|
String |
userName()
Name of the user running the query.
|
protected final ReaderLifecycle readerLifecycle
protected TupleMetadata readerSchema
protected boolean isSchemaComplete
protected int batchSize
protected CustomErrorContext baseErrorContext
protected CustomErrorContext readerErrorContext
public SchemaNegotiatorImpl(ReaderLifecycle readerLifecycle)
public boolean isProjectionEmpty()
SchemaNegotiator
isProjectionEmpty
in interface SchemaNegotiator
ResultSetLoader.skipRows(int)
to indicate the
row count, false if at least one column is projected and so
data must be written using the loaderpublic ProjectedColumn projectionFor(String colName)
projectionFor
in interface SchemaNegotiator
public TupleMetadata providedSchema()
SchemaNegotiator
If a schema is provided, the reader should use that schema, converting or ignoring columns as needed. A scan without a provided schema has a "dynamic" schema to be defined by the scan operator itself along with the column projection list.
The provided schema describes the columns that the reader is capable of providing. Any given query may choose to project a subset of these columns.
providedSchema
in interface SchemaNegotiator
null
if the schema should be computed dynamically
from the source schema and column projectionspublic TupleMetadata inputSchema()
SchemaNegotiator
If the type is LATE
(dynamic), then the reader can choose
the type. Subsequent readers in the same scan will then see the
same column as concrete, with the type selected by the present
reader.
The reader is free to add additional columns. The internal mechanism will just ignore those columns and return a dummy reader for them.
The reader is also free to ignore columns. In this case, the internal
mechanism will fill in NULL
or default values.
inputSchema
in interface SchemaNegotiator
public OperatorContext context()
context
in interface SchemaNegotiator
public CustomErrorContext parentErrorContext()
SchemaNegotiator
(Obtain the error context for this reader from the
ResultSetLoader
.
parentErrorContext
in interface SchemaNegotiator
public CustomErrorContext errorContext()
SchemaNegotiator
SchemaNegotiator.setErrorContext(CustomErrorContext)
.errorContext
in interface SchemaNegotiator
public void setErrorContext(CustomErrorContext errorContext)
SchemaNegotiator
setErrorContext
in interface SchemaNegotiator
public void tableSchema(TupleMetadata schema, boolean isComplete)
SchemaNegotiator
tableSchema
in interface SchemaNegotiator
schema
- the table schema if known at open timeisComplete
- true if the schema is complete: if it can be used
to define an empty schema-only batch for the first reader. Set to
false if the schema is partial: if the reader must read rows to
determine the full schemapublic void tableSchema(TupleMetadata schema)
tableSchema
in interface SchemaNegotiator
public void schemaIsComplete(boolean isComplete)
schemaIsComplete
in interface SchemaNegotiator
public boolean isSchemaComplete()
public void batchSize(int maxRecordsPerBatch)
SchemaNegotiator
batchSize
in interface SchemaNegotiator
maxRecordsPerBatch
- preferred number of record per batchpublic String userName()
SchemaNegotiator
userName
in interface SchemaNegotiator
public ResultSetLoader build()
build
in interface SchemaNegotiator
public StaticBatchBuilder implicitColumnsLoader()
public ManagedReader newReader(ReaderFactory<?> readerFactory) throws ManagedReader.EarlyEofException
ManagedReader.EarlyEofException
protected void onEndBatch()
Copyright © 1970 The Apache Software Foundation. All rights reserved.