Search in sources :

Example 6 with DefaultField

use of com.thinkbiganalytics.discovery.model.DefaultField in project kylo by Teradata.

the class DomainTypeIT method testCreateAndUpdateDatasource.

@Test
public void testCreateAndUpdateDatasource() {
    FieldStandardizationRule toUpperCase = new FieldStandardizationRule();
    FieldValidationRule email = new FieldValidationRule();
    toUpperCase.setName("Uppercase");
    toUpperCase.setDisplayName("Uppercase");
    toUpperCase.setDescription("Convert string to uppercase");
    toUpperCase.setObjectClassType("com.thinkbiganalytics.policy.standardization.UppercaseStandardizer");
    toUpperCase.setObjectShortClassType("UppercaseStandardizer");
    email.setName("email");
    email.setDisplayName("Email");
    email.setDescription("Valid email address");
    email.setObjectClassType("com.thinkbiganalytics.policy.validation.EmailValidator");
    email.setObjectShortClassType("EmailValidator");
    DomainType[] initialDomainTypes = getDomainTypes();
    // create new domain type
    DomainType dt = new DomainType();
    dt.setTitle("Domain Type 1");
    dt.setDescription("domain type created by integration tests");
    DomainType response = createDomainType(dt);
    assertEquals(dt.getTitle(), response.getTitle());
    assertEquals(dt.getDescription(), response.getDescription());
    assertEquals(null, response.getIcon());
    assertEquals(null, response.getIconColor());
    // assert new domain type was added
    DomainType[] currentDomainTypes = getDomainTypes();
    assertEquals(initialDomainTypes.length + 1, currentDomainTypes.length);
    // update existing domain type
    dt = getDomainType(response.getId());
    dt.setTitle("Domain Type 1 with updated title");
    dt.setDescription("domain type description updated by integration tests");
    dt.setIcon("stars");
    dt.setIconColor("green");
    DefaultField field = new DefaultField();
    Tag tag1 = new DefaultTag("tag1");
    Tag tag2 = new DefaultTag("tag2");
    field.setTags(Arrays.asList(tag1, tag2));
    field.setName("field-name");
    field.setDerivedDataType("decimal");
    field.setPrecisionScale("9, 3");
    dt.setField(field);
    dt.setFieldNamePattern("field-name-pattern");
    dt.setFieldPolicy(newPolicyBuilder(null).withStandardisation(toUpperCase).withValidation(email).toPolicy());
    dt.setRegexPattern("regex-pattern");
    DomainType updated = createDomainType(dt);
    assertEquals(dt.getTitle(), updated.getTitle());
    assertEquals(dt.getDescription(), updated.getDescription());
    assertEquals("stars", updated.getIcon());
    assertEquals("green", updated.getIconColor());
    Field updatedField = updated.getField();
    assertEquals(field.getName(), updatedField.getName());
    assertEquals(field.getDerivedDataType(), updatedField.getDerivedDataType());
    assertEquals(field.getPrecisionScale(), updatedField.getPrecisionScale());
    assertEquals(field.getTags().size(), updatedField.getTags().size());
    assertEquals(tag1.getName(), updatedField.getTags().get(0).getName());
    assertEquals(tag2.getName(), updatedField.getTags().get(1).getName());
    assertEquals(dt.getFieldNamePattern(), updated.getFieldNamePattern());
    assertEquals(dt.getRegexPattern(), updated.getRegexPattern());
    FieldStandardizationRule updatedStandardisation = updated.getFieldPolicy().getStandardization().get(0);
    assertEquals(toUpperCase.getName(), updatedStandardisation.getName());
    assertEquals(toUpperCase.getObjectShortClassType(), updatedStandardisation.getObjectShortClassType());
    FieldValidationRule updatedValidation = updated.getFieldPolicy().getValidation().get(0);
    assertEquals(email.getName(), updatedValidation.getName());
    assertEquals(email.getObjectShortClassType(), updatedValidation.getObjectShortClassType());
    // assert domain type was updated, rather than added
    currentDomainTypes = getDomainTypes();
    assertEquals(initialDomainTypes.length + 1, currentDomainTypes.length);
    // delete domain type
    deleteDomainType(dt.getId());
    currentDomainTypes = getDomainTypes();
    assertEquals(initialDomainTypes.length, currentDomainTypes.length);
    // assert domain type was removed
    getDomainTypeExpectingStatus(dt.getId(), HTTP_NOT_FOUND);
}
Also used : DefaultField(com.thinkbiganalytics.discovery.model.DefaultField) Field(com.thinkbiganalytics.discovery.schema.Field) DomainType(com.thinkbiganalytics.feedmgr.rest.model.DomainType) FieldValidationRule(com.thinkbiganalytics.policy.rest.model.FieldValidationRule) DefaultField(com.thinkbiganalytics.discovery.model.DefaultField) DefaultTag(com.thinkbiganalytics.discovery.model.DefaultTag) Tag(com.thinkbiganalytics.discovery.schema.Tag) DefaultTag(com.thinkbiganalytics.discovery.model.DefaultTag) FieldStandardizationRule(com.thinkbiganalytics.policy.rest.model.FieldStandardizationRule) Test(org.junit.Test)

Example 7 with DefaultField

use of com.thinkbiganalytics.discovery.model.DefaultField in project kylo by Teradata.

the class IntegrationTestBase method newNamedField.

protected DefaultField newNamedField(String name, DefaultDataTypeDescriptor typeDescriptor, String type) {
    DefaultField field = new DefaultField();
    field.setName(name);
    field.setDerivedDataType(type);
    field.setDataTypeDescriptor(typeDescriptor);
    return field;
}
Also used : DefaultField(com.thinkbiganalytics.discovery.model.DefaultField)

Example 8 with DefaultField

use of com.thinkbiganalytics.discovery.model.DefaultField in project kylo by Teradata.

the class SparkFileSchemaParserService method toHiveSchema.

private DefaultHiveSchema toHiveSchema(TransformQueryResult result, SparkFileType fileType) {
    DefaultHiveSchema schema = new DefaultHiveSchema();
    schema.setHiveFormat("STORED AS " + fileType);
    schema.setStructured(true);
    ArrayList<Field> fields = new ArrayList<>();
    List<? extends QueryResultColumn> columns = result.getColumns();
    for (int i = 0; i < columns.size(); ++i) {
        QueryResultColumn column = columns.get(i);
        DefaultField field = new DefaultField();
        field.setName(column.getDisplayName());
        field.setNativeDataType(column.getDataType());
        field.setDerivedDataType(column.getDataType());
        field.setDataTypeDescriptor(ParserHelper.hiveTypeToDescriptor(column.getDataType()));
        // strip the precisionScale and assign to the field property
        setPrecisionAndScale(field);
        // Add sample values
        List<List<Object>> values = result.getRows();
        for (List<Object> colMap : values) {
            Object oVal = colMap.get(i);
            if (oVal != null) {
                field.getSampleValues().add(oVal.toString());
            }
        }
        fields.add(field);
    }
    schema.setFields(fields);
    return schema;
}
Also used : DefaultField(com.thinkbiganalytics.discovery.model.DefaultField) Field(com.thinkbiganalytics.discovery.schema.Field) DefaultHiveSchema(com.thinkbiganalytics.discovery.model.DefaultHiveSchema) ArrayList(java.util.ArrayList) DefaultField(com.thinkbiganalytics.discovery.model.DefaultField) ArrayList(java.util.ArrayList) List(java.util.List) QueryResultColumn(com.thinkbiganalytics.discovery.schema.QueryResultColumn)

Example 9 with DefaultField

use of com.thinkbiganalytics.discovery.model.DefaultField in project kylo by Teradata.

the class HiveMetastoreService method getTable.

public TableSchema getTable(String schema, String table) throws DataAccessException {
    // Must use JDBC metadata for user impersonation
    if (userImpersonationEnabled) {
        return hiveService.getTableSchema(schema, table);
    }
    String query = "SELECT d.NAME as \"DATABASE_NAME\", t.TBL_NAME, c.COLUMN_NAME, c.TYPE_NAME " + "FROM COLUMNS_V2 c " + "JOIN  SDS s on s.CD_ID = c.CD_ID " + "JOIN  TBLS t ON s.SD_ID = t.SD_ID " + "JOIN  DBS d on d.DB_ID = t.DB_ID " + "WHERE t.TBL_NAME='" + table + "' and d.NAME='" + schema + "' " + "ORDER BY d.NAME, t.TBL_NAME, c.INTEGER_IDX";
    if (DatabaseType.POSTGRES.equals(getMetastoreDatabaseType())) {
        query = "SELECT d.\"NAME\" as \"DATABASE_NAME\", t.\"TBL_NAME\", c.\"COLUMN_NAME\",c.\"TYPE_NAME\" " + "FROM \"COLUMNS_V2\" c " + "JOIN  \"SDS\" s on s.\"CD_ID\" = c.\"CD_ID\" " + "JOIN  \"TBLS\" t ON s.\"SD_ID\" = t.\"SD_ID\" " + "JOIN  \"DBS\" d on d.\"DB_ID\" = t.\"DB_ID\" " + "WHERE t.\"TBL_NAME\"='" + table + "' and d.\"NAME\"='" + schema + "' " + "ORDER BY d.\"NAME\", t.\"TBL_NAME\", c.\"INTEGER_IDX\"";
    }
    final DefaultTableSchema metadata = new DefaultTableSchema();
    hiveMetatoreJdbcTemplate.query(query, new RowMapper<Object>() {

        @Override
        public TableSchema mapRow(ResultSet rs, int i) throws SQLException {
            String dbName = rs.getString("DATABASE_NAME");
            String columnName = rs.getString("COLUMN_NAME");
            String tableName = rs.getString("TBL_NAME");
            String columnType = rs.getString("TYPE_NAME");
            metadata.setName(tableName);
            metadata.setSchemaName(dbName);
            DefaultField field = new DefaultField();
            field.setName(columnName);
            field.setNativeDataType(columnType);
            field.setDerivedDataType(columnType);
            metadata.getFields().add(field);
            return metadata;
        }
    });
    return metadata;
}
Also used : TableSchema(com.thinkbiganalytics.discovery.schema.TableSchema) DefaultTableSchema(com.thinkbiganalytics.discovery.model.DefaultTableSchema) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DefaultTableSchema(com.thinkbiganalytics.discovery.model.DefaultTableSchema) DefaultField(com.thinkbiganalytics.discovery.model.DefaultField)

Aggregations

DefaultField (com.thinkbiganalytics.discovery.model.DefaultField)9 Field (com.thinkbiganalytics.discovery.schema.Field)5 ArrayList (java.util.ArrayList)4 DefaultTableSchema (com.thinkbiganalytics.discovery.model.DefaultTableSchema)3 TableSchema (com.thinkbiganalytics.discovery.schema.TableSchema)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DefaultFileSchema (com.thinkbiganalytics.discovery.model.DefaultFileSchema)1 DefaultHiveSchema (com.thinkbiganalytics.discovery.model.DefaultHiveSchema)1 DefaultTag (com.thinkbiganalytics.discovery.model.DefaultTag)1 QueryResultColumn (com.thinkbiganalytics.discovery.schema.QueryResultColumn)1 Tag (com.thinkbiganalytics.discovery.schema.Tag)1 DomainType (com.thinkbiganalytics.feedmgr.rest.model.DomainType)1 FeedCategory (com.thinkbiganalytics.feedmgr.rest.model.FeedCategory)1 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)1 FieldStandardizationRule (com.thinkbiganalytics.policy.rest.model.FieldStandardizationRule)1 FieldValidationRule (com.thinkbiganalytics.policy.rest.model.FieldValidationRule)1 HashMap (java.util.HashMap)1