Search in sources :

Example 71 with BusinessObjectDataDdlRequest

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

the class BusinessObjectDataServiceGenerateBusinessObjectDataDllCollectionTest method testGenerateBusinessObjectDataDdlCollectionMissingRequiredParameters.

@Test
public void testGenerateBusinessObjectDataDdlCollectionMissingRequiredParameters() {
    BusinessObjectDataDdlCollectionRequest request;
    // Try to generate business object data ddl collection collection when business object data ddl collection request is null.
    try {
        businessObjectDataService.generateBusinessObjectDataDdlCollection(null);
        fail("Should throw an IllegalArgumentException when business object data DDL collection request is null.");
    } catch (IllegalArgumentException e) {
        assertEquals("A business object data DDL collection request must be specified.", e.getMessage());
    }
    // Try to generate business object data ddl collection collection when business object data ddl request is not specified.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlCollectionRequest();
    for (List<BusinessObjectDataDdlRequest> businessObjectDataDdlRequests : Arrays.asList(null, new ArrayList<BusinessObjectDataDdlRequest>())) {
        request.setBusinessObjectDataDdlRequests(businessObjectDataDdlRequests);
        try {
            businessObjectDataService.generateBusinessObjectDataDdlCollection(request);
            fail("Should throw an IllegalArgumentException when business object data DDL request is not specified.");
        } catch (IllegalArgumentException e) {
            assertEquals("At least one business object data DDL request must be specified.", e.getMessage());
        }
    }
    // Try to generate business object data ddl collection collection when business object data ddl request is null.
    request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlCollectionRequest();
    request.getBusinessObjectDataDdlRequests().set(0, null);
    try {
        businessObjectDataService.generateBusinessObjectDataDdlCollection(request);
        fail("Should throw an IllegalArgumentException when business object data DDL request is null.");
    } catch (IllegalArgumentException e) {
        assertEquals("A business object data DDL request must be specified.", e.getMessage());
    }
}
Also used : BusinessObjectDataDdlCollectionRequest(org.finra.herd.model.api.xml.BusinessObjectDataDdlCollectionRequest) BusinessObjectDataDdlRequest(org.finra.herd.model.api.xml.BusinessObjectDataDdlRequest) Test(org.junit.Test)

Example 72 with BusinessObjectDataDdlRequest

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

the class BusinessObjectDataServiceGenerateBusinessObjectDataDdlTest method testGenerateBusinessObjectDataDdlMultipleStorages.

@Test
public void testGenerateBusinessObjectDataDdlMultipleStorages() {
    // Prepare database entities required for testing.
    businessObjectDataServiceTestHelper.createDatabaseEntitiesForBusinessObjectDataDdlTesting(FileTypeEntity.TXT_FILE_TYPE, FIRST_PARTITION_COLUMN_NAME, PARTITION_KEY_GROUP, BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, UNSORTED_PARTITION_VALUES, SUBPARTITION_VALUES, SCHEMA_DELIMITER_PIPE, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_NULL_VALUE_BACKSLASH_N, schemaColumnDaoTestHelper.getTestSchemaColumns(), schemaColumnDaoTestHelper.getTestPartitionColumns(), false, CUSTOM_DDL_NAME, true, ALLOW_DUPLICATE_BUSINESS_OBJECT_DATA);
    // Retrieve business object data ddl for data located in multiple storages.
    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, UNSORTED_PARTITION_VALUES, NO_PARTITION_VALUE_RANGE, NO_LATEST_BEFORE_PARTITION_VALUE, NO_LATEST_AFTER_PARTITION_VALUE)), NO_STANDALONE_PARTITION_VALUE_FILTER, DATA_VERSION, STORAGE_NAMES, NO_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, ALLOW_MISSING_DATA, NO_INCLUDE_ALL_REGISTERED_SUBPARTITIONS, NO_SUPPRESS_SCAN_FOR_UNREGISTERED_SUBPARTITIONS));
    // Validate the response object.
    String expectedDdl = businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataDdl(PARTITION_COLUMNS.length, FIRST_COLUMN_NAME, FIRST_COLUMN_DATA_TYPE, ROW_FORMAT, Hive13DdlGenerator.TEXT_HIVE_FILE_FORMAT, FileTypeEntity.TXT_FILE_TYPE, BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, MULTI_STORAGE_AVAILABLE_PARTITION_VALUES_UNION, SUBPARTITION_VALUES, false, true, true);
    assertEquals(new BusinessObjectDataDdl(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, FORMAT_VERSION, Arrays.asList(new PartitionValueFilter(FIRST_PARTITION_COLUMN_NAME, UNSORTED_PARTITION_VALUES, NO_PARTITION_VALUE_RANGE, NO_LATEST_BEFORE_PARTITION_VALUE, NO_LATEST_AFTER_PARTITION_VALUE)), NO_STANDALONE_PARTITION_VALUE_FILTER, DATA_VERSION, STORAGE_NAMES, NO_STORAGE_NAME, BusinessObjectDataDdlOutputFormatEnum.HIVE_13_DDL, TABLE_NAME, NO_CUSTOM_DDL_NAME, expectedDdl), resultBusinessObjectDataDdl);
}
Also used : 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 73 with BusinessObjectDataDdlRequest

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

the class BusinessObjectDataServiceGenerateBusinessObjectDataDdlTest method testGenerateBusinessObjectDataDdlLatestFormatHasLessPartitionColumnsThenBusinessObjectData.

/**
 * This test case reproduces an error when business object data has more or equal sub-partition values then the latest business object format version.
 */
@Test
public void testGenerateBusinessObjectDataDdlLatestFormatHasLessPartitionColumnsThenBusinessObjectData() {
    // 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, COLUMN_DEFAULT_VALUE, COLUMN_DESCRIPTION));
    // Build two list of partition columns, so the second format version would have one less partition column defined.
    List<SchemaColumn> partitionColumns1 = schemaColumns.subList(0, 2);
    List<SchemaColumn> partitionColumns2 = schemaColumns.subList(0, 1);
    // Create an initial version of business object format with the schema having two partition columns.
    BusinessObjectFormatEntity businessObjectFormatEntity1 = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, NO_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, partitionColumns1);
    // Create a second version of business object format with the schema having only one partition column.
    businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, SECOND_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, partitionColumns2);
    // Provide sub-partition column name and value.
    List<SchemaColumn> subPartitionColumns = partitionColumns1.subList(1, 2);
    List<String> subPartitionValues = Arrays.asList(SUBPARTITION_VALUES.get(0));
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectFormatEntity1, PARTITION_VALUE, subPartitionValues, DATA_VERSION, true, BusinessObjectDataStatusEntity.VALID);
    // Create an S3 storage entity.
    // Add the "bucket name" attribute to the storage along with the key prefix velocity template.
    StorageEntity storageEntity = storageDaoTestHelper.createStorageEntity(STORAGE_NAME, StoragePlatformEntity.S3, Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME), new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_KEY_PREFIX_VELOCITY_TEMPLATE), S3_KEY_PREFIX_VELOCITY_TEMPLATE)));
    // Build an S3 key prefix according to the Data Management S3 naming convention.
    String s3KeyPrefix = getExpectedS3KeyPrefix(NAMESPACE, DATA_PROVIDER_NAME, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, INITIAL_FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, subPartitionColumns.toArray(new SchemaColumn[subPartitionColumns.size()]), subPartitionValues.toArray(new String[subPartitionValues.size()]), DATA_VERSION);
    // Create a storage unit with a storage directory path.
    storageUnitDaoTestHelper.createStorageUnitEntity(storageEntity, businessObjectDataEntity, StorageUnitStatusEntity.ENABLED, s3KeyPrefix);
    // or equal sub-partition values then the latest business object format version.
    try {
        businessObjectDataService.generateBusinessObjectDataDdl(new BusinessObjectDataDdlRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, null, Arrays.asList(new PartitionValueFilter(PARTITION_KEY, Arrays.asList(PARTITION_VALUE), NO_PARTITION_VALUE_RANGE, NO_LATEST_BEFORE_PARTITION_VALUE, NO_LATEST_AFTER_PARTITION_VALUE)), NO_STANDALONE_PARTITION_VALUE_FILTER, null, 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));
        fail("Suppose to throw an IllegalArgumentException when business object data has more or " + "equal sub-partition values then the latest business object format version.");
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Number of subpartition values specified for the business object data is greater than or equal to " + "the number of partition columns defined in the schema of the business object format selected for DDL generation. " + "Business object data: {%s},  business object format: {%s}", businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, subPartitionValues, DATA_VERSION), businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatKeyAsString(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.TXT_FILE_TYPE, SECOND_FORMAT_VERSION)), e.getMessage());
    }
}
Also used : Attribute(org.finra.herd.model.api.xml.Attribute) 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) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) PartitionValueFilter(org.finra.herd.model.api.xml.PartitionValueFilter) Test(org.junit.Test)

Example 74 with BusinessObjectDataDdlRequest

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

the class BusinessObjectDataServiceGenerateBusinessObjectDataDdlTest method testGenerateBusinessObjectDataDdlLatestAfterPartitionValueNoStorage.

@Test
public void testGenerateBusinessObjectDataDdlLatestAfterPartitionValueNoStorage() {
    // Prepare database entities required for testing.
    businessObjectDataServiceTestHelper.createDatabaseEntitiesForBusinessObjectDataDdlTesting(PARTITION_VALUE_2);
    // Check an availability using a latest after partition value filter option and without specifying any storage.
    for (String lowerBoundPartitionValue : 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, NO_LATEST_BEFORE_PARTITION_VALUE, new LatestAfterPartitionValue(lowerBoundPartitionValue))), NO_STANDALONE_PARTITION_VALUE_FILTER, DATA_VERSION, NO_STORAGE_NAMES, NO_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, NO_LATEST_BEFORE_PARTITION_VALUE, new LatestAfterPartitionValue(lowerBoundPartitionValue))), NO_STANDALONE_PARTITION_VALUE_FILTER, DATA_VERSION, NO_STORAGE_NAMES, NO_STORAGE_NAME, BusinessObjectDataDdlOutputFormatEnum.HIVE_13_DDL, TABLE_NAME, NO_CUSTOM_DDL_NAME, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataDdl(PARTITION_VALUE_2)), resultBusinessObjectDataDdl);
    }
}
Also used : BusinessObjectDataDdlRequest(org.finra.herd.model.api.xml.BusinessObjectDataDdlRequest) BusinessObjectDataDdl(org.finra.herd.model.api.xml.BusinessObjectDataDdl) PartitionValueFilter(org.finra.herd.model.api.xml.PartitionValueFilter) LatestAfterPartitionValue(org.finra.herd.model.api.xml.LatestAfterPartitionValue) Test(org.junit.Test)

Example 75 with BusinessObjectDataDdlRequest

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

the class BusinessObjectDataServiceGenerateBusinessObjectDataDdlTest method testGenerateBusinessObjectDataDdlMissingBusinessObjectDataAllowMissingDataIncludeDropPartitionsDataNoExists.

@Test
public void testGenerateBusinessObjectDataDdlMissingBusinessObjectDataAllowMissingDataIncludeDropPartitionsDataNoExists() {
    // Prepare database entities required for testing.
    businessObjectDataServiceTestHelper.createDatabaseEntitiesForBusinessObjectDataDdlTesting(PARTITION_VALUE);
    // Retrieve business object data ddl when all of the business object data is not available
    // and both "allow missing data" and "include drop partitions" flags are set to "true".
    BusinessObjectDataDdlRequest request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataDdlRequest(Arrays.asList(PARTITION_VALUE_2));
    request.setIncludeDropPartitions(true);
    request.setAllowMissingData(true);
    BusinessObjectDataDdl result = businessObjectDataService.generateBusinessObjectDataDdl(request);
    // 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, Arrays.asList(PARTITION_VALUE_2), 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, businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataDdl(PARTITION_VALUE_2, null)), result);
}
Also used : 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)

Aggregations

BusinessObjectDataDdlRequest (org.finra.herd.model.api.xml.BusinessObjectDataDdlRequest)79 Test (org.junit.Test)74 BusinessObjectDataDdl (org.finra.herd.model.api.xml.BusinessObjectDataDdl)47 PartitionValueFilter (org.finra.herd.model.api.xml.PartitionValueFilter)32 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)22 ArrayList (java.util.ArrayList)14 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)13 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)9 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)5 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)5 StorageEntity (org.finra.herd.model.jpa.StorageEntity)5 LatestAfterPartitionValue (org.finra.herd.model.api.xml.LatestAfterPartitionValue)4 LatestBeforePartitionValue (org.finra.herd.model.api.xml.LatestBeforePartitionValue)4 HashMap (java.util.HashMap)3 Attribute (org.finra.herd.model.api.xml.Attribute)3 BusinessObjectDataDdlCollectionRequest (org.finra.herd.model.api.xml.BusinessObjectDataDdlCollectionRequest)3 FieldExtension (org.activiti.bpmn.model.FieldExtension)2 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)2 Parameter (org.finra.herd.model.api.xml.Parameter)2 PartitionValueRange (org.finra.herd.model.api.xml.PartitionValueRange)2