Package org.tribuo.data.sql
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 FieldProcessor
s to it.
The Connection
s 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
-
Field Summary
Fields inherited from class org.tribuo.data.columnar.ColumnarDataSource
outputRequired, rowProcessor
-
Constructor Summary
ConstructorDescriptionSQLDataSource
(String sqlString, SQLDBConfig sqlConfig, OutputFactory<T> outputFactory, RowProcessor<T> rowProcessor, boolean outputRequired) Constructs a SQLDataSource. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
The iterator that emitsColumnarIterator.Row
objects from the underlying data source.toString()
Methods inherited from class org.tribuo.data.columnar.ColumnarDataSource
getMetadataTypes, getOutputFactory, iterator
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.oracle.labs.mlrg.olcut.config.Configurable
postConfig
Methods 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:ColumnarDataSource
The iterator that emitsColumnarIterator.Row
objects from the underlying data source.- Specified by:
rowIterator
in classColumnarDataSource<T extends Output<T>>
- Returns:
- The row level iterator.
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-
getProvenance
-