Search in sources :

Example 11 with BusinessObjectDataDdl

use of org.finra.herd.model.api.xml.BusinessObjectDataDdl in project herd by FINRAOS.

the class BusinessObjectDataServiceGenerateBusinessObjectDataDdlTest method testGenerateBusinessObjectDataDdlNoPartitioning.

@Test
public void testGenerateBusinessObjectDataDdlNoPartitioning() {
    // Prepare non-partitioned test business object data with custom ddl.
    List<String> partitionValues = Arrays.asList(Hive13DdlGenerator.NO_PARTITIONING_PARTITION_VALUE);
    businessObjectDataServiceTestHelper.createDatabaseEntitiesForBusinessObjectDataDdlTesting(FileTypeEntity.TXT_FILE_TYPE, Hive13DdlGenerator.NO_PARTITIONING_PARTITION_KEY, null, BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, partitionValues, NO_SUBPARTITION_VALUES, SCHEMA_DELIMITER_PIPE, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_NULL_VALUE_BACKSLASH_N, schemaColumnDaoTestHelper.getTestSchemaColumns(), null, false, CUSTOM_DDL_NAME, true, ALLOW_DUPLICATE_BUSINESS_OBJECT_DATA);
    // Retrieve business object data ddl for a non-partitioned table.
    BusinessObjectDataDdlRequest request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(UNSORTED_PARTITION_VALUES, CUSTOM_DDL_NAME);
    request.getPartitionValueFilters().get(0).setPartitionKey(Hive13DdlGenerator.NO_PARTITIONING_PARTITION_KEY);
    request.getPartitionValueFilters().get(0).setPartitionValues(partitionValues);
    BusinessObjectDataDdl resultDdl = businessObjectDataService.generateBusinessObjectDataDdl(request);
    // Validate the results.
    String expectedDdl = businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataDdl(0, FIRST_COLUMN_NAME, FIRST_COLUMN_DATA_TYPE, ROW_FORMAT, Hive13DdlGenerator.TEXT_HIVE_FILE_FORMAT, FileTypeEntity.TXT_FILE_TYPE, BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, UNSORTED_PARTITION_VALUES, STORAGE_1_AVAILABLE_PARTITION_VALUES, false, true, true);
    businessObjectDataServiceTestHelper.validateBusinessObjectDataDdl(request, expectedDdl, resultDdl);
}
Also used : BusinessObjectDataDdlRequest(org.finra.herd.model.api.xml.BusinessObjectDataDdlRequest) BusinessObjectDataDdl(org.finra.herd.model.api.xml.BusinessObjectDataDdl) Test(org.junit.Test)

Example 12 with BusinessObjectDataDdl

use of org.finra.herd.model.api.xml.BusinessObjectDataDdl in project herd by FINRAOS.

the class BusinessObjectDataServiceGenerateBusinessObjectDataDdlTest method testGenerateBusinessObjectDataDdlLargePartitionValueListWithAutoDiscovery.

@Test
@Ignore
public void testGenerateBusinessObjectDataDdlLargePartitionValueListWithAutoDiscovery() {
    final int PRIMARY_PARTITION_VALUE_LIST_SIZE = 10000;
    final int SECOND_LEVEL_PARTITION_VALUES_PER_BUSINESS_OBJECT_DATA = 1;
    final int STORAGE_FILES_PER_PARTITION = 1;
    // Prepare test data and build a list of partition values to generate business object data DDL for.
    // Build a list of schema columns.
    List<SchemaColumn> schemaColumns = new ArrayList<>();
    schemaColumns.add(new SchemaColumn(PARTITION_KEY, "DATE", NO_COLUMN_SIZE, COLUMN_REQUIRED, NO_COLUMN_DEFAULT_VALUE, NO_COLUMN_DESCRIPTION));
    schemaColumns.add(new SchemaColumn(COLUMN_NAME, "NUMBER", COLUMN_SIZE, NO_COLUMN_REQUIRED, NO_COLUMN_DEFAULT_VALUE, COLUMN_DESCRIPTION));
    schemaColumns.add(new SchemaColumn(COLUMN_NAME_2, "STRING", NO_COLUMN_SIZE, NO_COLUMN_REQUIRED, NO_COLUMN_DEFAULT_VALUE, NO_COLUMN_DESCRIPTION));
    // Use the first two columns as partition columns.
    List<SchemaColumn> partitionColumns = schemaColumns.subList(0, 2);
    // Create a business object format entity with the schema.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, FORMAT_VERSION, FORMAT_DESCRIPTION, LATEST_VERSION_FLAG_SET, PARTITION_KEY, NO_PARTITION_KEY_GROUP, NO_ATTRIBUTES, SCHEMA_DELIMITER_PIPE, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_NULL_VALUE_BACKSLASH_N, schemaColumns, partitionColumns);
    // Create an S3 storage entity.
    StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME, StoragePlatformEntity.S3, configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME);
    // Create relative business object data, storage unit, and storage file entities.
    List<String> partitionValues = new ArrayList<>();
    for (int i = 0; i < PRIMARY_PARTITION_VALUE_LIST_SIZE; i++) {
        String partitionValue = String.format("%s-%03d", PARTITION_VALUE, i);
        partitionValues.add(partitionValue);
        // Create a business object data entity.
        BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectFormatEntity, partitionValue, NO_SUBPARTITION_VALUES, DATA_VERSION, true, BusinessObjectDataStatusEntity.VALID);
        // Build an S3 key prefix according to the herd S3 naming convention.
        String s3KeyPrefix = getExpectedS3KeyPrefix(NAMESPACE, DATA_PROVIDER_NAME, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, FORMAT_VERSION, PARTITION_KEY, partitionValue, null, null, DATA_VERSION);
        // Create a storage unit with a storage directory path.
        StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(storageEntity, businessObjectDataEntity, StorageUnitStatusEntity.ENABLED, s3KeyPrefix);
        // Create storage file entities.
        for (int j = 0; j < SECOND_LEVEL_PARTITION_VALUES_PER_BUSINESS_OBJECT_DATA; j++) {
            // Build a storage file directory path that includes the relative second level partition value - needed for auto discovery.
            String storageFileDirectoryPath = String.format("%s/%s=%s-%03d", s3KeyPrefix, COLUMN_NAME, PARTITION_VALUE_2, j);
            for (int k = 0; k < STORAGE_FILES_PER_PARTITION; k++) {
                String storageFilePath = String.format("%s/%03d.data", storageFileDirectoryPath, k);
                storageFileDaoTestHelper.createStorageFileEntity(storageUnitEntity, storageFilePath, FILE_SIZE_1_KB, ROW_COUNT_1000);
            }
        }
        herdDao.saveAndRefresh(storageUnitEntity);
    }
    // Retrieve business object data ddl for the entire list of partition values.
    BusinessObjectDataDdl businessObjectDataDdl = businessObjectDataService.generateBusinessObjectDataDdl(new BusinessObjectDataDdlRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, FORMAT_VERSION, Arrays.asList(new PartitionValueFilter(PARTITION_KEY, partitionValues, NO_PARTITION_VALUE_RANGE, NO_LATEST_BEFORE_PARTITION_VALUE, NO_LATEST_AFTER_PARTITION_VALUE)), NO_STANDALONE_PARTITION_VALUE_FILTER, DATA_VERSION, NO_STORAGE_NAMES, STORAGE_NAME, BusinessObjectDataDdlOutputFormatEnum.HIVE_13_DDL, TABLE_NAME, NO_CUSTOM_DDL_NAME, INCLUDE_DROP_TABLE_STATEMENT, INCLUDE_IF_NOT_EXISTS_OPTION, NO_INCLUDE_DROP_PARTITIONS, NO_ALLOW_MISSING_DATA, NO_INCLUDE_ALL_REGISTERED_SUBPARTITIONS, NO_SUPPRESS_SCAN_FOR_UNREGISTERED_SUBPARTITIONS));
    // Validate the results.
    assertNotNull(businessObjectDataDdl);
}
Also used : StorageUnitEntity(org.finra.herd.model.jpa.StorageUnitEntity) BusinessObjectDataDdlRequest(org.finra.herd.model.api.xml.BusinessObjectDataDdlRequest) SchemaColumn(org.finra.herd.model.api.xml.SchemaColumn) ArrayList(java.util.ArrayList) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectDataDdl(org.finra.herd.model.api.xml.BusinessObjectDataDdl) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) PartitionValueFilter(org.finra.herd.model.api.xml.PartitionValueFilter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with BusinessObjectDataDdl

use of org.finra.herd.model.api.xml.BusinessObjectDataDdl in project herd by FINRAOS.

the class BusinessObjectDataServiceGenerateBusinessObjectDataDdlTest method testGenerateBusinessObjectDataDdlLatestBeforePartitionValue.

@Test
public void testGenerateBusinessObjectDataDdlLatestBeforePartitionValue() {
    // Prepare database entities required for testing.
    businessObjectDataServiceTestHelper.createDatabaseEntitiesForBusinessObjectDataDdlTesting(PARTITION_VALUE);
    // Check an availability using a latest before partition value filter option.
    for (String upperBoundPartitionValue : Arrays.asList(PARTITION_VALUE, PARTITION_VALUE_2)) {
        BusinessObjectDataDdl resultBusinessObjectDataDdl = businessObjectDataService.generateBusinessObjectDataDdl(new BusinessObjectDataDdlRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, FORMAT_VERSION, Arrays.asList(new PartitionValueFilter(FIRST_PARTITION_COLUMN_NAME, NO_PARTITION_VALUES, NO_PARTITION_VALUE_RANGE, new LatestBeforePartitionValue(upperBoundPartitionValue), NO_LATEST_AFTER_PARTITION_VALUE)), NO_STANDALONE_PARTITION_VALUE_FILTER, DATA_VERSION, NO_STORAGE_NAMES, STORAGE_NAME, BusinessObjectDataDdlOutputFormatEnum.HIVE_13_DDL, TABLE_NAME, NO_CUSTOM_DDL_NAME, INCLUDE_DROP_TABLE_STATEMENT, INCLUDE_IF_NOT_EXISTS_OPTION, INCLUDE_DROP_PARTITIONS, NO_ALLOW_MISSING_DATA, NO_INCLUDE_ALL_REGISTERED_SUBPARTITIONS, NO_SUPPRESS_SCAN_FOR_UNREGISTERED_SUBPARTITIONS));
        // Validate the response object.
        assertEquals(new BusinessObjectDataDdl(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, FORMAT_VERSION, Arrays.asList(new PartitionValueFilter(FIRST_PARTITION_COLUMN_NAME, NO_PARTITION_VALUES, NO_PARTITION_VALUE_RANGE, new LatestBeforePartitionValue(upperBoundPartitionValue), NO_LATEST_AFTER_PARTITION_VALUE)), NO_STANDALONE_PARTITION_VALUE_FILTER, DATA_VERSION, NO_STORAGE_NAMES, STORAGE_NAME, BusinessObjectDataDdlOutputFormatEnum.HIVE_13_DDL, TABLE_NAME, NO_CUSTOM_DDL_NAME, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataDdl(PARTITION_VALUE)), resultBusinessObjectDataDdl);
    }
}
Also used : LatestBeforePartitionValue(org.finra.herd.model.api.xml.LatestBeforePartitionValue) BusinessObjectDataDdlRequest(org.finra.herd.model.api.xml.BusinessObjectDataDdlRequest) BusinessObjectDataDdl(org.finra.herd.model.api.xml.BusinessObjectDataDdl) PartitionValueFilter(org.finra.herd.model.api.xml.PartitionValueFilter) Test(org.junit.Test)

Example 14 with BusinessObjectDataDdl

use of org.finra.herd.model.api.xml.BusinessObjectDataDdl in project herd by FINRAOS.

the class BusinessObjectDataServiceGenerateBusinessObjectDataDdlTest method testGenerateBusinessObjectDataDdlLargePartitionValueListPrimaryPartitionOnly.

@Test
public void testGenerateBusinessObjectDataDdlLargePartitionValueListPrimaryPartitionOnly() {
    final int PRIMARY_PARTITION_VALUES_SIZE = 10000;
    // Prepare test data.
    businessObjectDataServiceTestHelper.createDatabaseEntitiesForBusinessObjectDataDdlTesting();
    BusinessObjectDataDdlRequest request;
    BusinessObjectDataDdl resultDdl;
    // Retrieve business object data ddl by passing a large set of partition values.
    List<String> partitionValues = new ArrayList<>();
    for (int i = 0; i < PRIMARY_PARTITION_VALUES_SIZE; i++) {
        partitionValues.add(String.format("%s-%s", PARTITION_VALUE, i));
    }
    partitionValues.addAll(UNSORTED_PARTITION_VALUES);
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(partitionValues, CUSTOM_DDL_NAME);
    resultDdl = businessObjectDataService.generateBusinessObjectDataDdl(request);
    // Validate the results.
    businessObjectDataServiceTestHelper.validateBusinessObjectDataDdl(request, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataDdl(), resultDdl);
    // Retrieve business object data ddl when request partition value list has duplicate values.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(UNSORTED_PARTITION_VALUES, CUSTOM_DDL_NAME);
    request.getPartitionValueFilters().get(0).getPartitionValues().add(UNSORTED_PARTITION_VALUES.get(0));
    resultDdl = businessObjectDataService.generateBusinessObjectDataDdl(request);
    // Validate the results.
    businessObjectDataServiceTestHelper.validateBusinessObjectDataDdl(request, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataDdl(), resultDdl);
}
Also used : BusinessObjectDataDdlRequest(org.finra.herd.model.api.xml.BusinessObjectDataDdlRequest) ArrayList(java.util.ArrayList) BusinessObjectDataDdl(org.finra.herd.model.api.xml.BusinessObjectDataDdl) Test(org.junit.Test)

Example 15 with BusinessObjectDataDdl

use of org.finra.herd.model.api.xml.BusinessObjectDataDdl in project herd by FINRAOS.

the class BusinessObjectDataServiceGenerateBusinessObjectDataDdlTest method testGenerateBusinessObjectDataDdlPartitionValueListStandalonePartitionValueFilter.

@Test
public void testGenerateBusinessObjectDataDdlPartitionValueListStandalonePartitionValueFilter() {
    // Prepare test data.
    businessObjectDataServiceTestHelper.createDatabaseEntitiesForBusinessObjectDataDdlTesting();
    BusinessObjectDataDdlRequest request;
    BusinessObjectDataDdl resultDdl;
    // Retrieve business object data ddl using request with a standalone partition value filter.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(UNSORTED_PARTITION_VALUES, CUSTOM_DDL_NAME);
    request.setPartitionValueFilter(request.getPartitionValueFilters().get(0));
    request.setPartitionValueFilters(null);
    resultDdl = businessObjectDataService.generateBusinessObjectDataDdl(request);
    // Validate the results.
    businessObjectDataServiceTestHelper.validateBusinessObjectDataDdl(request, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataDdl(), resultDdl);
}
Also used : BusinessObjectDataDdlRequest(org.finra.herd.model.api.xml.BusinessObjectDataDdlRequest) BusinessObjectDataDdl(org.finra.herd.model.api.xml.BusinessObjectDataDdl) Test(org.junit.Test)

Aggregations

BusinessObjectDataDdl (org.finra.herd.model.api.xml.BusinessObjectDataDdl)50 BusinessObjectDataDdlRequest (org.finra.herd.model.api.xml.BusinessObjectDataDdlRequest)47 Test (org.junit.Test)45 PartitionValueFilter (org.finra.herd.model.api.xml.PartitionValueFilter)16 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)16 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)8 ArrayList (java.util.ArrayList)6 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)4 StorageEntity (org.finra.herd.model.jpa.StorageEntity)4 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)3 HashMap (java.util.HashMap)2 BusinessObjectDataDdlCollectionResponse (org.finra.herd.model.api.xml.BusinessObjectDataDdlCollectionResponse)2 LatestAfterPartitionValue (org.finra.herd.model.api.xml.LatestAfterPartitionValue)2 LatestBeforePartitionValue (org.finra.herd.model.api.xml.LatestBeforePartitionValue)2 List (java.util.List)1 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1 Attribute (org.finra.herd.model.api.xml.Attribute)1 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)1 CustomDdlKey (org.finra.herd.model.api.xml.CustomDdlKey)1 CustomDdlEntity (org.finra.herd.model.jpa.CustomDdlEntity)1