Java Code Examples for org.pentaho.metadata.model.concept.types.DataType

The following examples show how to use org.pentaho.metadata.model.concept.types.DataType. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private Class<?> mapDataType( final DataType dataType ) {
  switch ( dataType ) {
    case UNKNOWN:
      return Object.class;
    case STRING:
      return String.class;
    case DATE:
      return Date.class;
    case BOOLEAN:
      return Boolean.class;
    case NUMERIC:
      return Number.class;
    case BINARY:
      return byte[].class;
    case IMAGE:
      return byte[].class;
    case URL:
      return Object.class;
    default:
      return Object.class;
  }
}
 
Example 2
private static DataType getDataType( ValueMetaInterface v ) {
  switch ( v.getType() ) {
    case ValueMetaInterface.TYPE_BIGNUMBER:
    case ValueMetaInterface.TYPE_INTEGER:
    case ValueMetaInterface.TYPE_NUMBER:
      return DataType.NUMERIC;
    case ValueMetaInterface.TYPE_BINARY:
      return DataType.BINARY;
    case ValueMetaInterface.TYPE_BOOLEAN:
      return DataType.BOOLEAN;
    case ValueMetaInterface.TYPE_DATE:
    case ValueMetaInterface.TYPE_TIMESTAMP:
      return DataType.DATE;
    case ValueMetaInterface.TYPE_STRING:
      return DataType.STRING;
    case ValueMetaInterface.TYPE_NONE:
    default:
      return DataType.UNKNOWN;
  }
  // the enum data type no longer supports length and precision
  // dataTypeSettings.setLength(v.getLength());
  // dataTypeSettings.setPrecision(v.getPrecision());

}
 
Example 3
private int convertType( DataType type ) {
  switch ( type ) {
    case DATE:
      return ValueMetaInterface.TYPE_DATE;
    case BOOLEAN:
      return ValueMetaInterface.TYPE_BOOLEAN;
    case NUMERIC:
      return ValueMetaInterface.TYPE_NUMBER;
    case BINARY:
    case IMAGE:
      return ValueMetaInterface.TYPE_BINARY;
    case UNKNOWN:
    case URL:
    case STRING:
    default:
      return ValueMetaInterface.TYPE_STRING;
  }
}
 
Example 4
@Test
public void testGetDataTypeTimestamp() throws Exception {
  final Database database = mock( Database.class );
  RowMeta rowMeta = new RowMeta();
  rowMeta.addValueMeta( new ValueMetaTimestamp( "ordertime" ) );
  DatabaseMeta databaseMeta = mock( DatabaseMeta.class );
  when( database.getDatabaseMeta() ).thenReturn( databaseMeta );
  when( databaseMeta.quoteField( "aSchema" ) ).thenReturn( "aSchema" );
  when( databaseMeta.quoteField( "aTable" ) ).thenReturn( "aTable" );
  when( databaseMeta.getSchemaTableCombination( "aSchema", "aTable" ) ).thenReturn( "aSchema.aTable" );
  when( database.getTableFields( "aSchema.aTable" ) ).thenReturn( rowMeta );

  SqlPhysicalTable physicalTable =
    importTableDefinition( database, "aSchema", "aTable", "klingon" );
  List<IPhysicalColumn> physicalColumns = physicalTable.getPhysicalColumns();

  assertEquals( 1, physicalColumns.size() );

  IPhysicalColumn column = physicalColumns.get( 0 );
  DataType dt = ( DataType ) column.getProperty( "datatype" );
  assertEquals( "Date", dt.getName() );
}
 
Example 5
@Test
public void testParseMutivaluedDefault_String() throws Exception {
  Object values = helper.parseDefaultValue( "a|b|c|d|e", DataType.STRING );
  assertTrue( values instanceof String[] );
  String[] stringValues = (String[]) values;
  assertEquals( 5, stringValues.length );
  assertEquals( "a", stringValues[0] );
  assertEquals( "b", stringValues[1] );
  assertEquals( "c", stringValues[2] );
  assertEquals( "d", stringValues[3] );
  assertEquals( "e", stringValues[4] );

  values = helper.parseDefaultValue( "a", DataType.STRING );
  assertTrue( values instanceof String );
  assertEquals( "a", values );

  // try "a|b"|"c|d"
  values = helper.parseDefaultValue( "\"a|b\"|\"c|d\"", DataType.STRING );
  assertTrue( values instanceof String[] );
  stringValues = (String[]) values;
  assertEquals( 2, stringValues.length );
  assertEquals( "a|b", stringValues[0] );
  assertEquals( "c|d", stringValues[1] );
}
 
Example 6
@Test
public void testDegenerateViewGenDate() throws Exception {
  LogicalModel businessModel = getTestModel( TargetTableType.INLINE_SQL, "select * from customer", "" );
  businessModel.getLogicalTables().get( 0 ).getLogicalColumns().get( 0 ).setDataType( DataType.DATE );
  MondrianModelExporter exporter = new MondrianModelExporter( businessModel, "en_US" );
  String data = exporter.createMondrianModelXML();

  TestHelper.assertEqualsIgnoreWhitespaces( "<Schema name=\"model\">\n" + "  <Dimension name=\"Dim1\">\n"
      + "    <Hierarchy name=\"Hier1\" hasAll=\"false\">\n" + "    <View alias=\"FACT\">\n"
      + "        <SQL dialect=\"generic\">\n" + "         <![CDATA[select * from customer]]>\n" + "        </SQL>\n"
      + "    </View>\n" + "      <Level name=\"Lvl1\" uniqueMembers=\"false\" column=\"pc1\" type=\"Date\">\n"
      + "      </Level>\n" + "    </Hierarchy>\n" + "  </Dimension>\n" + "  <Cube name=\"Cube1\">\n"
      + "    <View alias=\"FACT\">\n" + "        <SQL dialect=\"generic\">\n"
      + "         <![CDATA[select * from customer]]>\n" + "        </SQL>\n" + "    </View>\n"
      + "    <DimensionUsage name=\"Dim1\" source=\"Dim1\" foreignKey=\"pc2\"/>\n"
      + "    <Measure name=\"bc1\" column=\"pc1\" aggregator=\"sum\"/>\n" + "  </Cube>\n"
      + "</Schema>", data );
}
 
Example 7
private DataType getDataType( ColumnType type ) {
  switch ( type ) {
    case BOOLEAN:
      return DataType.BOOLEAN;
    case DATE:
      return DataType.DATE;
    case FLOAT:
    case NUMERIC:
      return DataType.NUMERIC;
    case TEXT:
      return DataType.STRING;
    default:
      return DataType.UNKNOWN;

  }
}
 
Example 8
private DataType getDataType( ColumnType type ) {
  switch ( type ) {
    case BOOLEAN:
      return DataType.BOOLEAN;
    case DATE:
      // As we are crafting an open formula function to handle dates, the parameter data type needs to be a String.
      // This will eventually be handled by the Metadata layer.
      return DataType.STRING;
      // return DataType.DATE;
    case FLOAT:
    case NUMERIC:
      return DataType.NUMERIC;
    case TEXT:
      return DataType.STRING;
    default:
      return DataType.UNKNOWN;

  }
}
 
Example 9
Source Project: pentaho-kettle   Source File: StarModelDialog.java    License: Apache License 2.0 6 votes vote down vote up
private void addLogicalColumnToFactAttributesList(LogicalColumn column) {
  TableItem item = new TableItem(wFactAttributes.table, SWT.NONE);

  //  name, description, physical column name, data type, length, precision, source db, source table, source column, conversion remarks
  //
  int col=1;
  item.setText(col++, Const.NVL(ConceptUtil.getName(column,locale), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getDescription(column, locale), ""));
  item.setText(col++, ConceptUtil.getAttributeType(column).name());
  item.setText(col++, Const.NVL((String)column.getProperty(DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME), ""));
  DataType dataType = (DataType) column.getProperty(DefaultPropertyID.DATA_TYPE.getId());
  item.setText(col++, dataType==null ? "" : dataType.name() );
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_DIMENSION_NAME), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_LENGTH), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_PRECISION), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_DB), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_TABLE), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_COLUMN), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_CONVERSION_REMARKS), ""));
}
 
Example 10
Source Project: pentaho-kettle   Source File: DimensionTableDialog.java    License: Apache License 2.0 6 votes vote down vote up
private void addAttributesFromFile(String filename) throws KettleException {
  InputStream inputStream = getClass().getResourceAsStream(filename);
  Document document = XMLHandler.loadXMLFile(inputStream);
  Node attributesNode = XMLHandler.getSubNode(document, "attributes");
  List<Node> attributeNodes = XMLHandler.getNodes(attributesNode, "attribute");
  for (Node node : attributeNodes) {
    String name = XMLHandler.getTagValue(node, "name");
    String description = XMLHandler.getTagValue(node, "description");
    String phName = XMLHandler.getTagValue(node, "physicalname");
    AttributeType attributeType= AttributeType.getAttributeType(XMLHandler.getTagValue(node, "attribute_type"));
    DataType dataType= ConceptUtil.getDataType(XMLHandler.getTagValue(node, "data_type"));
    int length = Const.toInt(XMLHandler.getTagValue(node, "length"), -1);
    int precision = Const.toInt(XMLHandler.getTagValue(node, "precision"), -1);
    // String sourceDb = XMLHandler.getTagValue(node, "source_db");
    // String sourceTable = XMLHandler.getTagValue(node, "source_table");
    // String sourceColumn = XMLHandler.getTagValue(node, "source_column");
    String remarks = XMLHandler.getTagValue(node, "remarks");
    addAttribute(name, description, phName, attributeType, dataType, length, precision, remarks);
  }

}
 
Example 11
Source Project: pentaho-kettle   Source File: DimensionTableDialog.java    License: Apache License 2.0 6 votes vote down vote up
private void addLogicalColumnToAttributesList(LogicalColumn column) {
  TableItem item = new TableItem(wAttributes.table, SWT.NONE);

  //  name, description, physical column name, data type, length, precision, source db, source table, source column, conversion remarks
  //
  int col=1;
  item.setText(col++, Const.NVL(ConceptUtil.getName(column,locale), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getDescription(column, locale), ""));
  item.setText(col++, ConceptUtil.getAttributeType(column).name());
  item.setText(col++, Const.NVL((String)column.getProperty(DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME), ""));
  DataType dataType = (DataType) column.getProperty(DefaultPropertyID.DATA_TYPE.getId());
  item.setText(col++, dataType==null ? "" : dataType.name() );
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_LENGTH), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_PRECISION), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_DB), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_TABLE), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_SOURCE_COLUMN), ""));
  item.setText(col++, Const.NVL(ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_CONVERSION_REMARKS), ""));
}
 
Example 12
public TableModel queryDesignTimeStructure( final String queryName,
                                            final DataRow parameter ) throws ReportDataFactoryException {
  final Query queryObject = parseQuery( queryName );
  List<Selection> selections = queryObject.getSelections();
  TypedMetaTableModel tableModel = new TypedMetaTableModel();
  for ( final Selection selection : selections ) {
    LogicalColumn logicalColumn = selection.getLogicalColumn();
    String id = logicalColumn.getId();
    DataType dataType = logicalColumn.getDataType();
    tableModel.addColumn( id, mapDataType( dataType ) );
  }
  return new PmdMetaTableModel( tableModel, selections );
}
 
Example 13
public static Object getValue( String valueAsString ) {
  if ( valueAsString != null ) {
    DataType type = getDataType( valueAsString );
    switch ( type ) {
      case STRING:
        return valueAsString;
      case BOOLEAN:
        return BooleanComparator.parseBoolean( valueAsString );
      case NUMERIC:
        return Integer.parseInt( valueAsString );
        // case DOUBLE:
        // return Double.parseDouble(valueAsString);
      case DATE:
        LocalDate localDate = new LocalDate( valueAsString );
        return new Date( new DateTime( localDate.getYear(), localDate.getMonthOfYear(), localDate.getDayOfMonth(), 0,
            0, 0, 0 ).getMillis() );
        /*
         * case TIME: LocalTime localTime = new LocalTime(valueAsString); return new Time(new DateTime(1970, 1, 1,
         * localTime .getHourOfDay(), localTime.getMinuteOfHour(), localTime .getSecondOfMinute(),
         * localTime.getMillisOfSecond()) .getMillis());
         */
      default:
        throw new IllegalStateException( Messages.getErrorString(
            "DataTypeDetector.ERROR_0001_UNSUPPORTED_COLUMN_TYPE", type ) ); //$NON-NLS-1$
    }
  }
  return null;
}
 
Example 14
public DataType evaluateDataType( List<String> columnValues ) {
  CountItemsList<DataType> columnTypes = new CountItemsList<DataType>();
  for ( String value : columnValues ) {
    DataType type = DataTypeDetector.getDataType( value );
    if ( type == DataType.STRING ) {
      return DataType.STRING;
    }
    columnTypes.add( type );
  }
  return columnTypes.getItemOfMaxCount();
}
 
Example 15
protected void addParameterFromXmlNode( Query query, Element paramElement ) {
  String name = paramElement.getAttribute( "name" ); //$NON-NLS-1$
  String type = paramElement.getAttribute( "type" ); //$NON-NLS-1$
  String defaultValue = paramElement.getAttribute( "defaultValue" ); //$NON-NLS-1$

  Object defaultVal = null;
  if ( name != null && type != null && StringUtils.isNotEmpty( defaultValue ) ) {
    DataType dataType = DataType.valueOf( type.toUpperCase() );
    defaultVal = parseDefaultValue( defaultValue, dataType );
  }
  Parameter param = new Parameter( name, DataType.valueOf( type.toUpperCase() ), defaultVal );
  query.getParameters().add( param );
}
 
Example 16
protected Object parseDefaultValue( String defaultValue, DataType dataType ) {
  if ( defaultValue == null ) {
    return null;
  }

  CSVTokenizer csvt = new CSVTokenizer( defaultValue, "|", "\"", true );
  switch ( dataType ) {
    case BOOLEAN:
      return parseBooleanDefaultParam( defaultValue, csvt );
    case NUMERIC:
      return parseDoubleDefaultParam( defaultValue, csvt );
    default:
      return parseStringDefaultParam( defaultValue, csvt );
  }
}
 
Example 17
public String getCondition( String type, String paramName ) {
  String[] val = this.value;
  /*
   * if(val == null && defaultValue != null) { val = defaultValue; }
   */
  Operator theOperator = Operator.parse( operator );
  if ( type.equalsIgnoreCase( DataType.STRING.getName() ) && theOperator == Operator.EQUAL ) {
    theOperator = Operator.EXACTLY_MATCHES;
  }

  boolean enforceParameters = isParameterized() && paramName != null;

  if ( !enforceParameters && type.equalsIgnoreCase( DataType.STRING.getName() ) ) {
    for ( int idx = 0; idx < val.length; idx++ ) {
      val[idx] = "\"" + val[idx] + "\""; //$NON-NLS-1$ //$NON-NLS-2$
    }
  }

  String columnName =
      "[" + parentId + "." + elementId + ( StringUtils.isEmpty( selectedAggregation ) ? "" : "." + selectedAggregation ) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$;
  // Date is a special case where we craft a formula function.
  if ( type.equals( DataType.DATE.getName() ) ) {
    if ( enforceParameters ) {
      // Due to the fact that the value of a Date is a forumula function, the tokenizing of
      // the value needs to happen here instead of letting the Operator class handle it.
      for ( int idx = 0; idx < val.length; idx++ ) {
        val[idx] = "DATEVALUE(" + "[param:" + value[idx].replaceAll( "[\\{\\}]", "" ) + "]" + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
      }
      return theOperator.formatCondition( columnName, paramName, val, false );
    } else {
      for ( int idx = 0; idx < val.length; idx++ ) {
        val[idx] = "DATEVALUE(\"" + val[idx] + "\")"; //$NON-NLS-1$ //$NON-NLS-2$
      }
    }
  }
  return theOperator.formatCondition( columnName, paramName, val, enforceParameters );
}
 
Example 18
/**
 * 
 * @param datatype
 *          should be one from {@link DataType}
 * @param mask
 * @param data
 * @return {@link String} - data which was formatted by mask or data if we have not correct mask
 */
public static String getFormatedString( DataType dataType, String mask, Object data ) {
  try {
    switch ( dataType ) {
      case NUMERIC:
        DecimalFormat decimalFormat = new DecimalFormat( mask );
        decimalFormat.setParseBigDecimal( true );
        return decimalFormat.format( data  );
      case DATE:
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat( mask );
        if ( data instanceof Date ) {
          return simpleDateFormat.format( data );
        }
        Date dateFromstring = DateDetector.getDateFromString( String.valueOf( data  ) );
        return simpleDateFormat.format( dateFromstring );
      case STRING:
      case UNKNOWN:
      case BOOLEAN:
      case BINARY:
      case IMAGE:
      case URL:
      default:
        return String.valueOf( data );
    }
  } catch ( Exception e ) {
    log.debug( DataFormatter.class.getName() + " could not apply mask to data. The original data was returned" ); //$NON-NLS-1$  //$NON-NLS-2$
    return String.valueOf( data );
  }
}
 
Example 19
public PropertyTypeRegistry() {
  // load these from a spring config file?
  addPropertyType( String.class );
  addPropertyType( LocalizedString.class );
  addPropertyType( DataType.class );
  addPropertyType( TargetTableType.class );
  addPropertyType( TargetColumnType.class );
  addPropertyType( AggregationType.class );

  // this is for agg lists,
  // we will need another way to express lists
  addPropertyType( List.class );

  addPropertyType( Alignment.class );
  addPropertyType( Color.class );
  addPropertyType( ColumnWidth.class );
  addPropertyType( FieldType.class );
  addPropertyType( Font.class );
  addPropertyType( TableType.class );
  addPropertyType( RowLevelSecurity.class );
  addPropertyType( Security.class );
  addPropertyType( Double.class );
  addPropertyType( Boolean.class );
  addPropertyType( Date.class );

  // note that URL is not GWT compatible, we'll need to figure out what to do with this
  // once we move towards a fully supported thin client metadata editor
  addPropertyType( URL.class );

}
 
Example 20
private static DataType converDataType( int type ) {
  switch ( type ) {
    case Types.FLOAT:
    case Types.BIT:
    case Types.DOUBLE:
    case Types.SMALLINT:
    case Types.REAL:
    case Types.DECIMAL:
    case Types.BIGINT:
    case Types.INTEGER:
    case Types.NUMERIC:
      return DataType.NUMERIC;

    case Types.BINARY:
    case Types.CLOB:
    case Types.BLOB:
      return DataType.BINARY;

    case Types.BOOLEAN:
      return DataType.BOOLEAN;

    case Types.DATE:
      return DataType.DATE;

    case Types.TIMESTAMP:
      return DataType.DATE;

    case Types.LONGVARCHAR:
    case Types.VARCHAR:
      return DataType.STRING;

    default:
      return DataType.UNKNOWN;
  }
}
 
Example 21
@Test
public void testQueryExecutionWithAggregationsAndConstraints() throws Exception {

  List<String> users = new ArrayList<String>();
  users.add( "suzy" );
  List<String> roles = new ArrayList<String>();
  roles.add( "Authenticated" );
  int defaultAcls = 31;
  InlineEtlModelGenerator gen =
      new InlineEtlModelGenerator( "testmodel", csvFilesPath, "example.csv", true,
          ",", "\"", true, users, roles, defaultAcls, "joe" );

  Domain domain = gen.generate();

  LogicalModel model = domain.getLogicalModels().get( 0 );
  Category category = model.getCategories().get( 0 );
  category.getLogicalColumns().get( 1 ).setDataType( DataType.NUMERIC );
  category.getLogicalColumns().get( 1 ).setAggregationType( AggregationType.SUM );
  Query query = new Query( domain, model );

  query.getSelections().add( new Selection( category, category.getLogicalColumns().get( 3 ), null ) );
  query.getSelections().add( new Selection( category, category.getLogicalColumns().get( 1 ), null ) );
  query.getConstraints().add( new Constraint( CombinationType.AND, "[bc_testmodel.bc_1_Data2] > 4.0" ) );
  query.getOrders().add(
      new Order( new Selection( category, category.getLogicalColumns().get( 3 ), null ), Order.Type.DESC ) );

  InlineEtlQueryExecutor executor = new InlineEtlQueryExecutor();
  IPentahoResultSet resultset = executor.executeQuery( query, csvFilesPath, null );

  Assert.assertEquals( 2, resultset.getRowCount() );
  Assert.assertEquals( 2, resultset.getColumnCount() );
  Assert.assertEquals( "bc_3_Data4", resultset.getMetaData().getColumnHeaders()[0][0] );
  Assert.assertEquals( "bc_1_Data2", resultset.getMetaData().getColumnHeaders()[0][1] );

  Assert.assertEquals( "String Value", resultset.getValueAt( 0, 0 ) );
  Assert.assertEquals( "Bigger String Value", resultset.getValueAt( 1, 0 ) );

  Assert.assertEquals( 19.5, resultset.getValueAt( 0, 1 ) );
  Assert.assertEquals( 5.7, resultset.getValueAt( 1, 1 ) );
}
 
Example 22
@Test
public void testParseMultivaluedDefault_Numeric() throws Exception {
  Object values = helper.parseDefaultValue( "1|2|3|4|5", DataType.NUMERIC );
  assertTrue( values instanceof Double[] );
  Double[] numericValues = (Double[]) values;
  assertEquals( 5, numericValues.length );
  assertEquals( 1D, numericValues[0] );
  assertEquals( 2D, numericValues[1] );
  assertEquals( 3D, numericValues[2] );
  assertEquals( 4D, numericValues[3] );
  assertEquals( 5D, numericValues[4] );
}
 
Example 23
@Test
public void testParseMultivaluedDefault_Boolean() throws Exception {
  Object values = helper.parseDefaultValue( "true|false", DataType.BOOLEAN );
  assertTrue( values instanceof Boolean[] );
  Boolean[] boolValues = (Boolean[]) values;
  assertEquals( 2, boolValues.length );
  assertTrue( boolValues[0] );
  assertFalse( boolValues[1] );
}
 
Example 24
@Test
public void testFormatString_Date() {
  assertEquals( expectedDate, DataFormatter.getFormatedString( DataType.DATE, SAMPLE_DATE_MASK, sampleJavaDate ) );
  assertEquals( expectedDate, DataFormatter.getFormatedString( DataType.DATE, SAMPLE_DATE_MASK, sampleSqlDate ) );
  assertEquals( expectedDate, DataFormatter.getFormatedString( DataType.DATE, SAMPLE_DATE_MASK, sampleSqlTimeStamp ) );
  assertEquals( expectedDate, DataFormatter.getFormatedString( DataType.DATE, SAMPLE_DATE_MASK, sampleStringDate ) );
  //should return data as string if we pass incorrect date
  assertEquals( SAMPLE_DATE_ERROR, DataFormatter.getFormatedString( DataType.DATE, SAMPLE_DATE_MASK, SAMPLE_DATE_ERROR ) );
}
 
Example 25
@Test
public void testFormatStringDataTypeAsString_Date() {
  assertEquals( expectedDate, DataFormatter.getFormatedString( DataType.DATE.toString(), SAMPLE_DATE_MASK, sampleJavaDate ) );
  assertEquals( expectedDate, DataFormatter.getFormatedString( DataType.DATE.toString(), SAMPLE_DATE_MASK, sampleSqlDate ) );
  assertEquals( expectedDate, DataFormatter.getFormatedString( DataType.DATE.toString(), SAMPLE_DATE_MASK, sampleSqlTimeStamp ) );
  assertEquals( expectedDate, DataFormatter.getFormatedString( DataType.DATE.toString(), SAMPLE_DATE_MASK, sampleStringDate ) );
  //should return data as string if we pass incorrect date
  assertEquals( SAMPLE_DATE_ERROR, DataFormatter.getFormatedString( DataType.DATE.toString(), SAMPLE_DATE_MASK, SAMPLE_DATE_ERROR ) );
}
 
Example 26
@Test
public void testGetDataType_Dates() {
  for ( String d : validDateSamples ) {
    DataType dt = DataTypeDetector.getDataType( d );
    assertEquals( "sample tested is not a recognized date format [" + d + "].", DataType.DATE, dt );
  }
}
 
Example 27
@Test
public void testGetDataType_NotDates() {
  for ( String d : nonValidDateSamples ) {
    DataType dt = DataTypeDetector.getDataType( d );
    assertFalse( "sample tested is a recognized date format [" + d + "]... it shouldn't be", DataType.DATE == dt );
  }
}
 
Example 28
@Test
public void testSampleData_String() throws Exception {
  List<String> columnValues = new ArrayList<String>();
  columnValues.add( "election day" );
  columnValues.add( "christmas day" );
  columnValues.add( "1212" );
  columnValues.add( "2323.33" );
  CsvDataTypeEvaluator type = new CsvDataTypeEvaluator( columnValues );
  DataType guessType = type.evaluateDataType( columnValues );
  Assert.assertEquals( DataType.STRING, guessType );
}
 
Example 29
@Test
public void testSampleData_Integer() throws Exception {
  List<String> columnValues = new ArrayList<String>();
  columnValues.add( "121212" );
  columnValues.add( "122" );
  columnValues.add( "1212" );
  columnValues.add( "2323.33" );
  CsvDataTypeEvaluator type = new CsvDataTypeEvaluator( columnValues );
  DataType guessType = type.evaluateDataType( columnValues );
  Assert.assertEquals( DataType.NUMERIC, guessType );
}
 
Example 30
@Test
public void testSampleData_Double() throws Exception {
  List<String> columnValues = new ArrayList<String>();
  columnValues.add( "121212" );
  columnValues.add( "232323.33" );
  columnValues.add( "3443.33" );
  columnValues.add( "2323.33" );
  CsvDataTypeEvaluator type = new CsvDataTypeEvaluator( columnValues );
  DataType guessType = type.evaluateDataType( columnValues );
  Assert.assertEquals( DataType.NUMERIC, guessType );
}