Class SchemaNegotiatorImpl
- All Implemented Interfaces:
SchemaNegotiator
- Direct Known Subclasses:
FileSchemaNegotiatorImpl
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.
-
Field Summary
Modifier and TypeFieldDescriptionprotected CustomErrorContext
protected int
protected boolean
protected CustomErrorContext
protected final ReaderLifecycle
protected TupleMetadata
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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.)build()
Callback from the schema negotiator to build the schema from information from both the table and scan operator.context()
Returns the error context to use for this reader: either the parent or the reader-specific context set inSchemaNegotiator.setErrorContext(CustomErrorContext)
.Returns the reader input schema: the schema which describes the set of columns this reader should produce.boolean
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
newReader
(ReaderFactory<?> readerFactory) protected void
The context to use as a parent when creating a custom context.projectionFor
(String colName) 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.userName()
Name of the user running the query.
-
Field Details
-
readerLifecycle
-
readerSchema
-
isSchemaComplete
protected boolean isSchemaComplete -
batchSize
protected int batchSize -
baseErrorContext
-
readerErrorContext
-
-
Constructor Details
-
SchemaNegotiatorImpl
-
-
Method Details
-
isProjectionEmpty
public boolean isProjectionEmpty()Description copied from interface:SchemaNegotiator
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.
- Specified by:
isProjectionEmpty
in interfaceSchemaNegotiator
- Returns:
- true if no columns are projected, and the client can
make use of
ResultSetLoader.skipRows(int)
to indicate the row count, false if at least one column is projected and so data must be written using the loader
-
projectionFor
- Specified by:
projectionFor
in interfaceSchemaNegotiator
-
providedSchema
Description copied from interface:SchemaNegotiator
Returns the provided schema, if defined. The provided schema is a description of the source schema viewed as a Drill schema.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.
- Specified by:
providedSchema
in interfaceSchemaNegotiator
- Returns:
- the provided schema if the execution plan defines the output
schema,
null
if the schema should be computed dynamically from the source schema and column projections
-
inputSchema
Description copied from interface:SchemaNegotiator
Returns the reader input schema: the schema which describes the set of columns this reader should produce. The schema can be fully dynamic (a wildcard), fully concrete (a list of columns and their types) or partially dynamic (a list of columns, but some types are not known.) If the reader has a choice of ways to map input columns to types, the reader must choose the type specified in the schema. Presumably, the specified types are those that the reader is capable of providing; there is no expectation that the reader will convert to arbitrary types.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.- Specified by:
inputSchema
in interfaceSchemaNegotiator
-
context
- Specified by:
context
in interfaceSchemaNegotiator
-
parentErrorContext
Description copied from interface:SchemaNegotiator
The context to use as a parent when creating a custom context.(Obtain the error context for this reader from the
ResultSetLoader
.- Specified by:
parentErrorContext
in interfaceSchemaNegotiator
-
errorContext
Description copied from interface:SchemaNegotiator
Returns the error context to use for this reader: either the parent or the reader-specific context set inSchemaNegotiator.setErrorContext(CustomErrorContext)
.- Specified by:
errorContext
in interfaceSchemaNegotiator
-
setErrorContext
Description copied from interface:SchemaNegotiator
Specify an advanced error context which allows the reader to fill in custom context values.- Specified by:
setErrorContext
in interfaceSchemaNegotiator
-
tableSchema
Description copied from interface:SchemaNegotiator
Specify the table schema if this is an early-schema reader. Need not be called for a late-schema readers. The schema provided here, if any, is a base schema: the reader is free to discover additional columns during the read.- Specified by:
tableSchema
in interfaceSchemaNegotiator
- Parameters:
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 schema
-
tableSchema
- Specified by:
tableSchema
in interfaceSchemaNegotiator
-
schemaIsComplete
public void schemaIsComplete(boolean isComplete) - Specified by:
schemaIsComplete
in interfaceSchemaNegotiator
-
isSchemaComplete
public boolean isSchemaComplete() -
batchSize
public void batchSize(int maxRecordsPerBatch) Description copied from interface:SchemaNegotiator
Set the preferred batch size (which may be overridden by the result set loader in order to limit vector or batch size.)- Specified by:
batchSize
in interfaceSchemaNegotiator
- Parameters:
maxRecordsPerBatch
- preferred number of record per batch
-
userName
Description copied from interface:SchemaNegotiator
Name of the user running the query.- Specified by:
userName
in interfaceSchemaNegotiator
-
build
Callback from the schema negotiator to build the schema from information from both the table and scan operator. Returns the result set loader to be used by the reader to write to the table's value vectors.- Specified by:
build
in interfaceSchemaNegotiator
- Returns:
- the result set loader to be used by the reader
-
implicitColumnsLoader
-
newReader
public ManagedReader newReader(ReaderFactory<?> readerFactory) throws ManagedReader.EarlyEofException - Throws:
ManagedReader.EarlyEofException
-
onEndBatch
protected void onEndBatch()
-