Class TablePlanRead

All Implemented Interfaces:
TablePlan

public class TablePlanRead extends TablePlanCommon<TablePlanRead>
Reads rows into a TableColumnar.

Example:


 StreamSource streamSource = StreamSources.fromString("Code,Amount\nabc,10.5\n", "values.csv");
 ReadOptionsCsv options = ReadOptionsCsv.builder().withSeparator(',').build();
 RowSource rowSource = RowSources.create(options, streamSource);

 TableColumnar table = new TablePlanRead().withTableName(TableName.of("Trades")).execute(rowSource);
 

There are two useful layers for column typing when reading:

- source-side types from RowCursor.columns() choose the low-level builder before rows are consumed and are therefore the best place to avoid intermediate string materialisation when that direct parser is genuinely worthwhile

- plan-side types configured on this class describe the desired output type and can override the source-side type when appropriate

  • Constructor Details

    • TablePlanRead

      public TablePlanRead()
  • Method Details

    • withIncludeResourceName

      public TablePlanRead withIncludeResourceName(ColumnName resourceName)
    • getResourceName

      public ColumnName getResourceName()
    • withLocalDateFormat

      public TablePlanRead withLocalDateFormat(DateFormat localDateFormat)
    • getLocalDateFormat

      public DateFormat getLocalDateFormat()
    • withTransform

      public TablePlanRead withTransform(Transform transform)
    • withTransforms

      public TablePlanRead withTransforms(Transform... transforms)
    • getTransforms

      public List<Transform> getTransforms()
    • withHeaderStrategy

      public TablePlanRead withHeaderStrategy(HeaderStrategy headerStrategy)
    • getHeaderStrategy

      public HeaderStrategy getHeaderStrategy()
    • withSelectedColumn

      public TablePlanRead withSelectedColumn(ColumnName columnName)
    • withSelectedColumns

      public TablePlanRead withSelectedColumns(ColumnName... columnNames)
    • withSelectedColumns

      public TablePlanRead withSelectedColumns(Collection<ColumnName> columnNames)
    • withSelectedColumns

      public TablePlanRead withSelectedColumns(Iterable<ColumnName> columnNames)
    • getSelectedColumns

      public Set<ColumnName> getSelectedColumns()
    • withColumnRename

      public TablePlanRead withColumnRename(ColumnName original, ColumnName newName)
    • withColumnRenames

      public TablePlanRead withColumnRenames(Map<ColumnName,ColumnName> renames)
    • getColumnRenames

      public Map<ColumnName,ColumnName> getColumnRenames()
    • withRowFilter

      public TablePlanRead withRowFilter(RowFilter rowFilter)
    • getRowFilter

      public RowFilter getRowFilter()
    • withStripping

      public TablePlanRead withStripping(boolean stripping)
    • isStripping

      public boolean isStripping()
    • withColumnType

      public TablePlanRead withColumnType(ColumnName columnName, Column.Type columnType)
      Specifies the desired output type for a column in the resulting table.

      This is best thought of as plan-side type intent. If the source cursor also exposes a type for the same column, that source-side type can still matter earlier because it may choose the low-level builder before rows are read.

      In other words:

      - source-side types are the right place to request direct builder parsing and bypass intermediate strings when the parser has a real advantage

      - plan-side types are the right place to describe the desired result schema or override the source metadata

      Parameters:
      columnName - the output column name
      columnType - the desired output type
      Returns:
      this plan
    • withColumnTypes

      public TablePlanRead withColumnTypes(Column.Type columnType, ColumnName... columnNames)
    • getColumnType

      public Column.Type getColumnType(ColumnName columnName)
    • getColumnTypes

      public Map<ColumnName,Column.Type> getColumnTypes()
    • execute

      public TableColumnar execute(TableName tableName, Column... columns)
    • execute

      public TableColumnar execute(TableName tableName, TableDescription tableDescription, Column... columns)
    • execute

      public TableColumnar execute(TableColumnar table)
    • execute

      public TableColumnar execute(RowCursor rowCursor)
      Description copied from interface: TablePlan
      Executes this plan against an already-open row supplier.

      Use this lower-level entry point when the caller already owns the live source resource and wants to control its lifetime explicitly.

      CSV example:

      
       StreamSource streamSource = ...;
       TablePlanRead plan = new TablePlanRead();
      
       ReadOptionsCsv options = ReadOptionsCsv.builder().withSeparator(';').build();
       try (InputStream inputStream = streamSource.openStream();
               RowCursor rowCursor = RowCursors.create(options, inputStream))
       {
           TableColumnar table = plan.execute(rowCursor);
       }
       
      JDBC example:
      
       PreparedStatement preparedStatement = ...;
       TablePlanRead plan = new TablePlanRead();
      
       try (ResultSet resultSet = preparedStatement.executeQuery();
               RowCursor rowCursor = new RowCursorResultSet(resultSet))
       {
           TableColumnar table = plan.execute(rowCursor);
       }
       
      Parameters:
      rowCursor - open row supplier to consume
      Returns:
      the resulting table
    • execute

      public TableColumnar execute(StreamSource streamSource)
      Reads the supplied stream source as CSV using ReadOptionsCsv.standard() defaults.
      Parameters:
      streamSource - the CSV stream source
      Returns:
      the parsed table
    • execute

      public TableColumnar execute(RowSource rowSource)
      Description copied from interface: TablePlan
      Executes this plan against a configured row source.

      This is the simplest high-level entry point when the source should handle opening and closing its own row supplier internally.

      CSV example:

      
       StreamSource streamSource = ...;
       TablePlanRead plan = new TablePlanRead();
      
       ReadOptionsCsv options = ReadOptionsCsv.builder().withSeparator(';').build();
       TableColumnar table = plan.execute(RowSources.create(options, streamSource));
       
      JDBC example:
      
       PreparedStatement preparedStatement = ...;
       TablePlanRead plan = new TablePlanRead();
      
       TableColumnar table = plan.execute(RowSourceResultSet.builder()
               .withPreparedStatement(preparedStatement)
               .build());
       
      Parameters:
      rowSource - configured source that opens rows for this execution
      Returns:
      the resulting table
    • self

      protected TablePlanRead self()
      Specified by:
      self in class TablePlanCommon<TablePlanRead>