net.sf.farrago.namespace.flatfile
Class FlatFileProgramWriter

java.lang.Object
  extended by net.sf.farrago.namespace.flatfile.FlatFileProgramWriter

public class FlatFileProgramWriter
extends Object

FlatFileProgramWriter builds calculator programs for converting text from flat files into typed data. It assumes the text has already been processed for quoting and escape characters. The programs mainly consist of simple casts. However, custom date formats may be specified when using LucidDb. They are implemented with calls to LucidDb user defined routines. Only one set of formats can be active for a writer.

When using custom date conversions, the program can be split into Fennel and Java-only sections. If splitting the program, data must flow through the Fennel section first, which handles basic casts. Then the Java-only section handles custom date conversions.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/namespace/flatfile/FlatFileProgramWriter.java#2 $
Author:
jpham

Nested Class Summary
private static class FlatFileProgramWriter.Section
          Identifies a section of a flat file program
 
Field Summary
private  String dateFormat
           
private static int DATETIME_FORMAT_ARG_LENGTH
           
private  RelDataType[] datetimeArgs
           
static int FLAT_FILE_MAX_NON_CHAR_VALUE_LEN
           
private  RexBuilder rexBuilder
           
private  RelDataType rowType
           
private  FarragoPreparingStmt stmt
           
private  String timeFormat
           
private  String timestampFormat
           
private static SqlIdentifier toDateFuncName
           
private static SqlIdentifier toTimeFuncName
           
private static SqlIdentifier toTimestampFuncName
           
private  RelDataTypeFactory typeFactory
           
 
Constructor Summary
FlatFileProgramWriter(RexBuilder rexBuilder, FarragoPreparingStmt stmt, FlatFileParams params, RelDataType rowType)
          Constructs a new FlatFileProgramWriter
 
Method Summary
 RexProgram getFennelSection()
          Gets the Fennel portion of the data conversion program
private  String getFormat(RelDataType type)
          Returns the custom format for a data type
 RexProgram getJavaOnlySection()
          Gets the Java only portion of the data conversion program
 RexProgram getProgram()
          Gets the entire data conversion program
private  RexProgram getSection(FlatFileProgramWriter.Section section)
          Builds a section of the data conversion program as follows.
private  RelDataType getTextType(RelDataType sqlType)
          Converts a SQL type into a type that can be used by a Fennel FlatFileExecStream to read files.
private  SqlFunction getUdr(RelDataType type, RelDataType charType)
          Gets a function that converts a string to another type, according to a format string.
private  boolean isCustom(RelDataType type)
          Whether a data type has a custom format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FLAT_FILE_MAX_NON_CHAR_VALUE_LEN

public static final int FLAT_FILE_MAX_NON_CHAR_VALUE_LEN
See Also:
Constant Field Values

toDateFuncName

private static final SqlIdentifier toDateFuncName

toTimeFuncName

private static final SqlIdentifier toTimeFuncName

toTimestampFuncName

private static final SqlIdentifier toTimestampFuncName

DATETIME_FORMAT_ARG_LENGTH

private static final int DATETIME_FORMAT_ARG_LENGTH
See Also:
Constant Field Values

rexBuilder

private final RexBuilder rexBuilder

typeFactory

private final RelDataTypeFactory typeFactory

stmt

private final FarragoPreparingStmt stmt

dateFormat

private final String dateFormat

timeFormat

private final String timeFormat

timestampFormat

private final String timestampFormat

datetimeArgs

private final RelDataType[] datetimeArgs

rowType

private final RelDataType rowType
Constructor Detail

FlatFileProgramWriter

public FlatFileProgramWriter(RexBuilder rexBuilder,
                             FarragoPreparingStmt stmt,
                             FlatFileParams params,
                             RelDataType rowType)
Constructs a new FlatFileProgramWriter

Parameters:
rexBuilder - a rex node builder
stmt - the statement being prepared
params - a set of flat file server parameters. These parameters may include custom date formats
rowType - the desired data type for data read from a flat file. The row type is also used to infer the size of text fields in the file.
Method Detail

getProgram

public RexProgram getProgram()
Gets the entire data conversion program


getFennelSection

public RexProgram getFennelSection()
Gets the Fennel portion of the data conversion program


getJavaOnlySection

public RexProgram getJavaOnlySection()
Gets the Java only portion of the data conversion program

Returns:
the program, or null if it is empty

getSection

private RexProgram getSection(FlatFileProgramWriter.Section section)
Builds a section of the data conversion program as follows.

Parameters:
section - section of the program to build
Returns:
the program section

getTextType

private RelDataType getTextType(RelDataType sqlType)
Converts a SQL type into a type that can be used by a Fennel FlatFileExecStream to read files.


isCustom

private boolean isCustom(RelDataType type)
Whether a data type has a custom format


getFormat

private String getFormat(RelDataType type)
Returns the custom format for a data type


getUdr

private SqlFunction getUdr(RelDataType type,
                           RelDataType charType)
Gets a function that converts a string to another type, according to a format string. Throws an exception if the function was not found.

Parameters:
type - the target type
charType - the type of the string
Returns:
a matching conversion function