Class CsvDBLoader


  • public class CsvDBLoader
    extends DBLoader
    Implementation of DBLoader which gets its Tables by reading CSV files using the CsvLoader class and is the loader use for CSV junit tests.

    CsvDBLoader requires that the CSV files have a specific format as defined:

     list_of_csv_files : (csv_file)+
     csv_file: table_definitions
     table_definitions: (table_definition)+
     table_definition: actions table_name column_names column_types
              (file_name or nos_of_rows or rows)
     actions: (action)*
     action: '##' (ActionBefore: | ActionAfter:) action_type
     action_type: DropIndex index_name | CreateIndex index_name column_name
     table_name: '##' TableName: table_name
     column_names: '##' ColumnNames: column_name (',' column_name)*
     column_types: '##' ColumnTypes: column_types ('.' column_types)*
     file_name:'##' FileName: relative_filename ?
     nos_of_rows:'##' NosOfRows: number
     column_types: type (':' null)
     type: "INTEGER" "DECIMAL(*,*)" "SMALLINT"
           "VARCHAR(*)" "REAL" "BOOLEAN"
           "BIGINT" "DATE" "TIMESTAMP"
      rows: (row)*
      row: value (',' value)*
    
      if FileName is given, then
          there is no NosOfRows
          the file can only contains rows
      else if NosOfRows is given, then
          there is no FileName
          the number of rows in current file are rows for table
      else
          the all remaining rows in current file are rows for table
      fi
    
      comment lines start with '#'
    
     

    See the testsrc/main/mondrian/rolap/aggmatcher/BUG_1541077.csv file for an example.

    Author:
    Richard M. Emberson
    • Constructor Detail

      • CsvDBLoader

        public CsvDBLoader()
    • Method Detail

      • setInputDirectory

        public void setInputDirectory​(java.io.File inputDirectory)
      • getInputDirectory

        public java.io.File getInputDirectory()
      • setInputDirectoryRegex

        public void setInputDirectoryRegex​(java.lang.String inputDirectoryRegex)
      • getInputDirectoryRegex

        public java.lang.String getInputDirectoryRegex()
      • setInputFiles

        public void setInputFiles​(java.io.File[] inputFiles)
      • getInputFiles

        public java.io.File[] getInputFiles()
      • setInputFile

        public void setInputFile​(java.io.File inputFile)
      • getInputFile

        public java.io.File getInputFile()
      • getTablesFromDirectory

        public DBLoader.Table[] getTablesFromDirectory()
                                                throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getTablesFromFiles

        public DBLoader.Table[] getTablesFromFiles()
                                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getTablesFromFile

        public DBLoader.Table[] getTablesFromFile()
                                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getTables

        public DBLoader.Table[] getTables​(java.io.File[] files)
                                   throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getTables

        public DBLoader.Table[] getTables​(java.io.Reader reader)
                                   throws java.lang.Exception
        Throws:
        java.lang.Exception
      • loadTables

        public void loadTables​(java.io.File file,
                               java.util.List<DBLoader.Table> tableList)
                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • loadTables

        public void loadTables​(java.io.Reader reader,
                               java.util.List<DBLoader.Table> tableList)
                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • loadColumns

        protected DBLoader.Column[] loadColumns​(java.lang.String[] columnNames,
                                                java.lang.String[] columnTypes,
                                                int lineNos)
                                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • check

        protected void check()
                      throws java.lang.Exception
        Overrides:
        check in class DBLoader
        Throws:
        java.lang.Exception
      • checkDirectory

        protected static java.io.File checkDirectory​(java.lang.String dirName)
                                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • usage

        protected static void usage​(java.lang.String msg)
      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.Exception
        Throws:
        java.lang.Exception