use of com.thinkbiganalytics.policy.FieldPolicy in project kylo by Teradata.
the class CleanseAndValidateRowTest method standardizeAndValidate.
@Test
public void standardizeAndValidate() {
String fieldName = "field1";
List<BaseFieldPolicy> policies = new ArrayList<>();
policies.add(new SimpleRegexReplacer("(?i)foo", "bar"));
policies.add(new LookupValidator("aabaraa"));
policies.add(new SimpleRegexReplacer("(?i)bar", "test"));
policies.add(new LookupValidator("aatestaa"));
FieldPolicy fieldPolicy = FieldPolicyBuilder.newBuilder().addPolicies(policies).tableName("emp").fieldName(fieldName).feedFieldName(fieldName).build();
HCatDataType fieldDataType = HCatDataType.createFromDataType(fieldName, "string");
StandardizationAndValidationResult result = validator.standardizeAndValidateField(fieldPolicy, "aafooaa", fieldDataType, new HashMap<Class, Class>());
assertEquals(result.getFieldValue(), "aatestaa");
assertEquals(StandardDataValidator.VALID_RESULT, result.getFinalValidationResult());
}
use of com.thinkbiganalytics.policy.FieldPolicy in project kylo by Teradata.
the class CleanseAndValidateRowTest method nullValueStandardizeAndValidate.
@Test
public void nullValueStandardizeAndValidate() {
String fieldName = "field1";
List<BaseFieldPolicy> policies = new ArrayList<>();
policies.add(new SimpleRegexReplacer("(?i)foo", "bar"));
policies.add(new LookupValidator("blah"));
policies.add(new SimpleRegexReplacer("(?i)bar", "test"));
policies.add(new LookupValidator("aatestaa"));
FieldPolicy fieldPolicy = FieldPolicyBuilder.newBuilder().addPolicies(policies).tableName("emp").fieldName(fieldName).feedFieldName(fieldName).build();
HCatDataType fieldDataType = HCatDataType.createFromDataType(fieldName, "string");
StandardizationAndValidationResult result = validator.standardizeAndValidateField(fieldPolicy, null, fieldDataType, new HashMap<Class, Class>());
assertEquals(StandardDataValidator.VALID_RESULT, result.getFinalValidationResult());
}
use of com.thinkbiganalytics.policy.FieldPolicy in project kylo by Teradata.
the class CleanseAndValidateRowTest method exceptionsShouldNotStopStandardization.
@Test
public void exceptionsShouldNotStopStandardization() {
StandardizationPolicy standardizer = EXCEPTION_POLICY;
String fieldName = "field1";
List<BaseFieldPolicy> policies = new ArrayList<>();
policies.add(standardizer);
FieldPolicy fieldPolicy = FieldPolicyBuilder.newBuilder().addPolicies(policies).tableName("emp").fieldName(fieldName).feedFieldName(fieldName).build();
HCatDataType fieldDataType = HCatDataType.createFromDataType(fieldName, "string");
StandardizationAndValidationResult result = validator.standardizeAndValidateField(fieldPolicy, "aafooaa", fieldDataType, new HashMap<Class, Class>());
assertEquals(result.getFieldValue(), "aafooaa");
}
use of com.thinkbiganalytics.policy.FieldPolicy in project kylo by Teradata.
the class CleanseAndValidateRowTest method standardizeShouldNotChangeType.
@Test
public void standardizeShouldNotChangeType() {
String fieldName = "field1";
List<BaseFieldPolicy> policies = new ArrayList<>();
policies.add(ADD_ONE_STANDARDISATION_POLICY);
policies.add(ADD_ONE_STANDARDISATION_POLICY);
FieldPolicy fieldPolicy = FieldPolicyBuilder.newBuilder().addPolicies(policies).tableName("temp").fieldName(fieldName).feedFieldName(fieldName).build();
HCatDataType fieldDataType = HCatDataType.createFromDataType(fieldName, "int");
StandardizationAndValidationResult result = validator.standardizeAndValidateField(fieldPolicy, 0, fieldDataType, new HashMap<Class, Class>());
assertEquals(2, result.getFieldValue());
assertEquals(StandardDataValidator.VALID_RESULT, result.getFinalValidationResult());
}
use of com.thinkbiganalytics.policy.FieldPolicy in project kylo by Teradata.
the class CleanseAndValidateRowTest method notNullValidate.
private ValidationResult notNullValidate(String dataType, String value, boolean allowEmptyString, boolean trimString) {
NotNullValidator validatorPolicy = new NotNullValidator(allowEmptyString, trimString);
List<BaseFieldPolicy> policies = new ArrayList<>();
policies.add(validatorPolicy);
FieldPolicy fieldPolicy = FieldPolicyBuilder.newBuilder().addPolicies(policies).tableName("emp").fieldName("field1").feedFieldName("field1").build();
StandardizationAndValidationResult result = validator.standardizeAndValidateField(fieldPolicy, value, HCatDataType.createFromDataType("field1", dataType), new HashMap<Class, Class>());
return result.getFinalValidationResult();
}
Aggregations