Class SQLDataSource<T extends Output<T>>
java.lang.Object
org.tribuo.data.columnar.ColumnarDataSource<T>
org.tribuo.data.sql.SQLDataSource<T>
- All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.config.Configurable,com.oracle.labs.mlrg.olcut.provenance.Provenancable<DataSourceProvenance>,AutoCloseable,Iterable<Example<T>>,ConfigurableDataSource<T>,DataSource<T>
public class SQLDataSource<T extends Output<T>>
extends ColumnarDataSource<T>
implements AutoCloseable
A
DataSource for loading columnar data from a database
and applying FieldProcessors to it.
The Connections it creates are closed when the iterator is empty
(ie. when hasNext is called and returns false). Calling close() on SQLDatasource itself closes all connections
created since close was last called.
N.B. This class accepts raw SQL strings and executes them directly via JDBC. It DOES NOT perform any SQL escaping or other injection prevention. It is the user's responsibility to ensure that SQL passed to this class performs as desired.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class org.tribuo.data.columnar.ColumnarDataSource
outputRequired, rowProcessor -
Constructor Summary
ConstructorsConstructorDescriptionSQLDataSource(String sqlString, SQLDBConfig sqlConfig, OutputFactory<T> outputFactory, RowProcessor<T> rowProcessor, boolean outputRequired) Constructs a SQLDataSource. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()The iterator that emitsColumnarIterator.Rowobjects from the underlying data source.toString()Methods inherited from class org.tribuo.data.columnar.ColumnarDataSource
getMetadataTypes, getOutputFactory, iteratorMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.oracle.labs.mlrg.olcut.config.Configurable
postConfigMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
SQLDataSource
public SQLDataSource(String sqlString, SQLDBConfig sqlConfig, OutputFactory<T> outputFactory, RowProcessor<T> rowProcessor, boolean outputRequired) throws SQLException Constructs a SQLDataSource.- Parameters:
sqlString- The SQL query to run.sqlConfig- The SQL connection configuration.outputFactory- The output factory to use.rowProcessor- The row processor to convert the returned rows into examples.outputRequired- Is an output required from this source.- Throws:
SQLException- If the database could not be read.
-
-
Method Details
-
toString
-
rowIterator
Description copied from class:ColumnarDataSourceThe iterator that emitsColumnarIterator.Rowobjects from the underlying data source.- Specified by:
rowIteratorin classColumnarDataSource<T extends Output<T>>- Returns:
- The row level iterator.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
getProvenance
-