org.pentaho.metadata.model.concept.types.DataType Java Examples
The following examples show how to use
org.pentaho.metadata.model.concept.types.DataType.
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
Source File: DimensionTableDialog.java From pentaho-kettle with Apache License 2.0 | 6 votes |
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 #2
Source File: PhysicalTableImporter.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
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
Source File: SimplePmdDataFactory.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
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 #4
Source File: InlineEtlQueryExecutor.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
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 #5
Source File: PhysicalTableImporterTest.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
@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 #6
Source File: QueryXmlHelperTest.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
@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 #7
Source File: MondrianModelExporterTest.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
@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 #8
Source File: MQLEditorServiceCWMDelegate.java From mql-editor with GNU Lesser General Public License v2.1 | 6 votes |
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 #9
Source File: MQLEditorServiceDelegate.java From mql-editor with GNU Lesser General Public License v2.1 | 6 votes |
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 #10
Source File: StarModelDialog.java From pentaho-kettle with Apache License 2.0 | 6 votes |
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 #11
Source File: DimensionTableDialog.java From pentaho-kettle with Apache License 2.0 | 6 votes |
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 #12
Source File: DataTypeDetectorTest.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@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 #13
Source File: DimensionTableDialog.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private void addAttribute(String name, String description, String phName, AttributeType attributeType, DataType dataType, int length, int precision, String comment) { LogicalColumn column = new LogicalColumn(); column.setLogicalTable(logicalTable); column.setName(new LocalizedString(locale, name)); column.setDescription(new LocalizedString(locale, description)); column.setDataType(dataType); column.setProperty(DefaultIDs.LOGICAL_COLUMN_ATTRIBUTE_TYPE, attributeType.name()); column.setProperty(DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME, phName); if (length>=0) column.setProperty(DefaultIDs.LOGICAL_COLUMN_LENGTH, Integer.toString(length)); if (precision>=0) column.setProperty(DefaultIDs.LOGICAL_COLUMN_PRECISION, Integer.toString(precision)); column.setProperty(DefaultIDs.LOGICAL_COLUMN_CONVERSION_REMARKS, comment); addLogicalColumnToAttributesList(column); }
Example #14
Source File: Condition.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
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 #15
Source File: SimplePmdDataFactory.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
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 #16
Source File: JobGenerator.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private ValueMetaInterface getValueForLogicalColumn(DatabaseMeta databaseMeta, LogicalColumn column) { String columnName = ConceptUtil.getName(column, locale); String phColumnName = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_PHYSICAL_COLUMN_NAME); DataType columnType = column.getDataType(); String lengthString = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_LENGTH); int length = Const.toInt(lengthString, -1); String precisionString = ConceptUtil.getString(column, DefaultIDs.LOGICAL_COLUMN_PRECISION); int precision = Const.toInt(precisionString, -1); int type=ValueMetaInterface.TYPE_STRING; switch(columnType) { case UNKNOWN: case URL: case STRING: precision=-1; break; case IMAGE: case BINARY: type = ValueMetaInterface.TYPE_BINARY; precision=-1; break; case BOOLEAN: type = ValueMetaInterface.TYPE_BOOLEAN; length=-1; precision=-1; break; case DATE: type = ValueMetaInterface.TYPE_DATE; length=-1; precision=-1; break; case NUMERIC: if (precision<=0 && length<15) { type = ValueMetaInterface.TYPE_INTEGER; } else { if (length>=15) { type = ValueMetaInterface.TYPE_BIGNUMBER; } else { type = ValueMetaInterface.TYPE_NUMBER; } } break; default: break; } ValueMetaInterface value = new ValueMeta(databaseMeta.quoteField(Const.NVL(phColumnName, columnName)), type); value.setLength(length, precision); return value; }
Example #17
Source File: QueryXmlHelper.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
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 #18
Source File: CsvDataTypeEvaluatorTest.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@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 #19
Source File: CsvDataTypeEvaluatorTest.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testSampleData_Boolean() throws Exception { List<String> columnValues = new ArrayList<String>(); columnValues.add( "true" ); columnValues.add( "1" ); columnValues.add( "false" ); columnValues.add( "false" ); CsvDataTypeEvaluator type = new CsvDataTypeEvaluator( columnValues ); DataType guessType = type.evaluateDataType( columnValues ); Assert.assertEquals( DataType.BOOLEAN, guessType ); }
Example #20
Source File: InlineEtlModelGeneratorIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@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 #21
Source File: CsvDataTypeEvaluatorTest.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testSampleData_Date() throws Exception { List<String> columnValues = new ArrayList<String>(); columnValues.add( "2008-11-04" ); columnValues.add( "2008-04-04" ); columnValues.add( "2008-05-04" ); columnValues.add( "2323.33" ); columnValues.add( "23.33" ); CsvDataTypeEvaluator type = new CsvDataTypeEvaluator( columnValues ); DataType guessType = type.evaluateDataType( columnValues ); Assert.assertEquals( DataType.DATE, guessType ); }
Example #22
Source File: CsvDataTypeEvaluatorTest.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testSampleData_Time() throws Exception { List<String> columnValues = new ArrayList<String>(); columnValues.add( "16:45" ); columnValues.add( "8:30" ); columnValues.add( "1212" ); columnValues.add( "23:40" ); CsvDataTypeEvaluator type = new CsvDataTypeEvaluator( columnValues ); DataType guessType = type.evaluateDataType( columnValues ); Assert.assertEquals( DataType.DATE, guessType ); }
Example #23
Source File: CsvDataTypeEvaluator.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
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 #24
Source File: DataTypeDetector.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
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 #25
Source File: QueryXmlHelperTest.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@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 #26
Source File: QueryXmlHelperTest.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@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 #27
Source File: CsvDataTypeEvaluatorTest.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@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 ); }
Example #28
Source File: CsvDataTypeEvaluatorTest.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@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 #29
Source File: DataFormatterTest.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
@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 #30
Source File: SQLModelGenerator.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
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; } }