use of org.talend.dataquality.statistics.type.DataTypeEnum in project data-prep by Talend.
the class TypeUtilsTest method testConvertDate.
@Test
public void testConvertDate() throws Exception {
ColumnMetadata metadata = column().id(1).type(Type.DATE).build();
final DataTypeEnum[] types = TypeUtils.convert(Collections.singletonList(metadata));
assertThat(types[0], is(DataTypeEnum.DATE));
}
use of org.talend.dataquality.statistics.type.DataTypeEnum in project data-prep by Talend.
the class StreamDateHistogramAnalyzer method analyze.
@Override
public boolean analyze(String... record) {
if (record.length != types.length) {
throw new IllegalArgumentException("Each column of the record should be declared a DataType.Type corresponding! \n" + types.length + " type(s) declared in this histogram analyzer but " + record.length + " column(s) was found in this record. \n" + "Using method: setTypes(DataType.Type[] types) to set the types. ");
}
stats.resize(record.length);
for (int index = 0; index < types.length; ++index) {
final DataTypeEnum type = this.types[index];
final ColumnMetadata column = this.columns.get(index);
final String value = record[index];
if (type == DataTypeEnum.DATE) {
final String mostUsedDatePattern = RowMetadataUtils.getMostUsedDatePattern(column);
if (!TypeInferenceUtils.isDate(value, Collections.singletonList(mostUsedDatePattern))) {
LOGGER.trace("Skip date value '{}' (not valid date)", value);
continue;
}
try {
final LocalDateTime adaptedValue = dateParser.parse(value, column);
stats.get(index).add(adaptedValue);
} catch (DateTimeException e) {
// just skip this value
LOGGER.debug("Unable to process date value '{}'", value, e);
}
}
}
return true;
}
use of org.talend.dataquality.statistics.type.DataTypeEnum in project data-prep by Talend.
the class TypeUtilsTest method testConvertBoolean.
@Test
public void testConvertBoolean() throws Exception {
ColumnMetadata metadata = column().id(1).type(Type.BOOLEAN).build();
final DataTypeEnum[] types = TypeUtils.convert(Collections.singletonList(metadata));
assertThat(types[0], is(DataTypeEnum.BOOLEAN));
}
use of org.talend.dataquality.statistics.type.DataTypeEnum in project data-prep by Talend.
the class TypeUtilsTest method testConvertString.
@Test
public void testConvertString() throws Exception {
ColumnMetadata metadata = column().id(1).type(Type.ANY).build();
DataTypeEnum[] types = TypeUtils.convert(Collections.singletonList(metadata));
assertThat(types[0], is(DataTypeEnum.STRING));
metadata = column().id(2).type(Type.STRING).build();
types = TypeUtils.convert(Collections.singletonList(metadata));
assertThat(types[0], is(DataTypeEnum.STRING));
}
use of org.talend.dataquality.statistics.type.DataTypeEnum in project data-prep by Talend.
the class TypeUtilsTest method testConvertInteger.
@Test
public void testConvertInteger() throws Exception {
ColumnMetadata metadata = column().id(1).type(Type.NUMERIC).build();
DataTypeEnum[] types = TypeUtils.convert(Collections.singletonList(metadata));
assertThat(types[0], is(DataTypeEnum.INTEGER));
metadata = column().id(2).type(Type.INTEGER).build();
types = TypeUtils.convert(Collections.singletonList(metadata));
assertThat(types[0], is(DataTypeEnum.INTEGER));
}
Aggregations