Search in sources :

Example 76 with PartitionValueFilter

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

the class BusinessObjectDataServiceCheckBusinessObjectDataAvailabilityTest method testCheckBusinessObjectDataAvailabilityMultiplePartitionValueFilters.

/**
 * This test validates the getBusinessObjectDataEntities() functionality when request contains multiple partition value filters and when business object
 * data entities actually exist.
 */
@Test
public void testCheckBusinessObjectDataAvailabilityMultiplePartitionValueFilters() {
    final int PRIMARY_PARTITION_VALUES_SIZE = 5;
    String[][] subPartitionValues = new String[][] { { null, null, null, null }, { "A", null, null, null }, { "A", "X", null, null }, { "A", "X", "0", null }, { "A", "X", "0", "0" }, { "A", "X", "0", "1" }, { "A", "X", "1", "0" }, { "A", "X", "1", "1" }, { "A", "Y", "0", "0" }, { "A", "Y", "0", "1" }, { "A", "Y", "1", "0" }, { "A", "Y", "1", "1" } };
    String[] secondStorageSubPartitionValues = new String[] { "A", "X", "2", "2" };
    // Create the relative database entities.
    List<SchemaColumn> columns = schemaColumnDaoTestHelper.getTestSchemaColumns();
    List<SchemaColumn> partitionColumns = schemaColumnDaoTestHelper.getTestPartitionColumns();
    String partitionKey = partitionColumns.get(0).getName();
    // Create a business object format entity with the schema.
    businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, FORMAT_DESCRIPTION, LATEST_VERSION_FLAG_SET, partitionKey, NO_PARTITION_KEY_GROUP, NO_ATTRIBUTES, SCHEMA_DELIMITER_PIPE, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_NULL_VALUE_BACKSLASH_N, columns, partitionColumns);
    // Create two storage entities if they do not exist.
    List<StorageEntity> storageEntities = Arrays.asList(storageDaoTestHelper.createStorageEntity(STORAGE_NAME), storageDaoTestHelper.createStorageEntity(STORAGE_NAME_2));
    // Create the relative business object data entities with the relative storage units.
    // Please note that we will create some extra business object data entities that
    // will not be selected as available per partition value mismatch or a different storage.
    List<String> primaryPartitionValues = new ArrayList<>();
    for (int i = 0; i < PRIMARY_PARTITION_VALUES_SIZE; i++) {
        BusinessObjectDataEntity businessObjectDataEntity;
        String primaryPartitionValue = String.format("%s-%s", PARTITION_VALUE, i);
        primaryPartitionValues.add(primaryPartitionValue);
        for (String[] subPartitionValuesSet : subPartitionValues) {
            businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, primaryPartitionValue, Arrays.asList(subPartitionValuesSet), DATA_VERSION, true, BusinessObjectDataStatusEntity.VALID);
            storageUnitDaoTestHelper.createStorageUnitEntity(storageEntities.get(0), businessObjectDataEntity, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
        }
        // Add an extra business object data that is only present in the second storage.
        businessObjectDataEntity = businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, primaryPartitionValue, Arrays.asList(secondStorageSubPartitionValues), DATA_VERSION, true, BusinessObjectDataStatusEntity.VALID);
        storageUnitDaoTestHelper.createStorageUnitEntity(storageEntities.get(1), businessObjectDataEntity, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
    }
    // Check business object data availability request with a large list of partition values using multiple partition value filters.
    BusinessObjectDataAvailabilityRequest request = businessObjectDataServiceTestHelper.getTestBusinessObjectDataAvailabilityRequest(null);
    List<PartitionValueFilter> partitionValueFilters = new ArrayList<>();
    request.setPartitionValueFilters(partitionValueFilters);
    partitionValueFilters.add(new PartitionValueFilter(partitionColumns.get(0).getName(), primaryPartitionValues, NO_PARTITION_VALUE_RANGE, NO_LATEST_BEFORE_PARTITION_VALUE, NO_LATEST_AFTER_PARTITION_VALUE));
    partitionValueFilters.add(new PartitionValueFilter(partitionColumns.get(1).getName(), Arrays.asList("A"), NO_PARTITION_VALUE_RANGE, NO_LATEST_BEFORE_PARTITION_VALUE, NO_LATEST_AFTER_PARTITION_VALUE));
    partitionValueFilters.add(new PartitionValueFilter(partitionColumns.get(2).getName(), Arrays.asList("X", "Y"), NO_PARTITION_VALUE_RANGE, NO_LATEST_BEFORE_PARTITION_VALUE, NO_LATEST_AFTER_PARTITION_VALUE));
    partitionValueFilters.add(new PartitionValueFilter(partitionColumns.get(3).getName(), Arrays.asList("0", "1"), NO_PARTITION_VALUE_RANGE, NO_LATEST_BEFORE_PARTITION_VALUE, NO_LATEST_AFTER_PARTITION_VALUE));
    partitionValueFilters.add(new PartitionValueFilter(partitionColumns.get(4).getName(), Arrays.asList("0", "1"), NO_PARTITION_VALUE_RANGE, NO_LATEST_BEFORE_PARTITION_VALUE, NO_LATEST_AFTER_PARTITION_VALUE));
    request.setBusinessObjectFormatVersion(null);
    request.setBusinessObjectDataVersion(null);
    BusinessObjectDataAvailability resultAvailability = businessObjectDataService.checkBusinessObjectDataAvailability(request);
    // Validate the results.
    assertNotNull(resultAvailability);
    assertEquals(PRIMARY_PARTITION_VALUES_SIZE * 8, resultAvailability.getAvailableStatuses().size());
    assertEquals(0, resultAvailability.getNotAvailableStatuses().size());
}
Also used : BusinessObjectDataAvailabilityRequest(org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityRequest) SchemaColumn(org.finra.herd.model.api.xml.SchemaColumn) ArrayList(java.util.ArrayList) BusinessObjectDataAvailability(org.finra.herd.model.api.xml.BusinessObjectDataAvailability) StorageEntity(org.finra.herd.model.jpa.StorageEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) PartitionValueFilter(org.finra.herd.model.api.xml.PartitionValueFilter) Test(org.junit.Test)

Example 77 with PartitionValueFilter

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

the class BusinessObjectDataServiceCheckBusinessObjectDataAvailabilityTest method testCheckBusinessObjectDataAvailabilityMultipleStorages.

@Test
public void testCheckBusinessObjectDataAvailabilityMultipleStorages() {
    // Create database entities required for testing.
    businessObjectDataAvailabilityTestHelper.createDatabaseEntitiesForBusinessObjectDataAvailabilityTesting(null, new ArrayList<>(), new ArrayList<>(), BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, SUBPARTITION_VALUES, ALLOW_DUPLICATE_BUSINESS_OBJECT_DATA);
    // Check business object data availability in multiple storages.
    BusinessObjectDataAvailability resultBusinessObjectDataAvailability = businessObjectDataService.checkBusinessObjectDataAvailability(new BusinessObjectDataAvailabilityRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, Arrays.asList(new PartitionValueFilter(PARTITION_KEY, UNSORTED_PARTITION_VALUES, NO_PARTITION_VALUE_RANGE, NO_LATEST_BEFORE_PARTITION_VALUE, NO_LATEST_AFTER_PARTITION_VALUE)), null, DATA_VERSION, STORAGE_NAMES, NO_STORAGE_NAME, NO_INCLUDE_ALL_REGISTERED_SUBPARTITIONS));
    // Validate the response object.
    assertEquals(new BusinessObjectDataAvailability(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, Arrays.asList(new PartitionValueFilter(PARTITION_KEY, UNSORTED_PARTITION_VALUES, NO_PARTITION_VALUE_RANGE, NO_LATEST_BEFORE_PARTITION_VALUE, NO_LATEST_AFTER_PARTITION_VALUE)), null, DATA_VERSION, STORAGE_NAMES, NO_STORAGE_NAME, businessObjectDataServiceTestHelper.getTestBusinessObjectDataStatuses(FORMAT_VERSION, BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, MULTI_STORAGE_AVAILABLE_PARTITION_VALUES_UNION, SUBPARTITION_VALUES, DATA_VERSION, BusinessObjectDataStatusEntity.VALID, false), businessObjectDataServiceTestHelper.getTestBusinessObjectDataStatuses(FORMAT_VERSION, BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, MULTI_STORAGE_NOT_AVAILABLE_PARTITION_VALUES, null, DATA_VERSION, BusinessObjectDataServiceImpl.REASON_NOT_REGISTERED, false)), resultBusinessObjectDataAvailability);
}
Also used : BusinessObjectDataAvailabilityRequest(org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityRequest) BusinessObjectDataAvailability(org.finra.herd.model.api.xml.BusinessObjectDataAvailability) PartitionValueFilter(org.finra.herd.model.api.xml.PartitionValueFilter) Test(org.junit.Test)

Example 78 with PartitionValueFilter

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

the class BusinessObjectDataServiceCheckBusinessObjectDataAvailabilityTest method testCheckBusinessObjectDataAvailabilityNoStorageNamesAndSameBusinessObjectDataInMultipleStorages.

@Test
public void testCheckBusinessObjectDataAvailabilityNoStorageNamesAndSameBusinessObjectDataInMultipleStorages() {
    // Prepare database entities required for testing.
    businessObjectDataAvailabilityTestHelper.createDatabaseEntitiesForBusinessObjectDataAvailabilityTesting(null, new ArrayList<>(), new ArrayList<>(), BusinessObjectDataEntity.FIRST_PARTITION_COLUMN_POSITION, SUBPARTITION_VALUES, ALLOW_DUPLICATE_BUSINESS_OBJECT_DATA);
    // and the same business object data is registered in multiple storages.
    try {
        businessObjectDataService.checkBusinessObjectDataAvailability(new BusinessObjectDataAvailabilityRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, Arrays.asList(new PartitionValueFilter(PARTITION_KEY, UNSORTED_PARTITION_VALUES, NO_PARTITION_VALUE_RANGE, NO_LATEST_BEFORE_PARTITION_VALUE, NO_LATEST_AFTER_PARTITION_VALUE)), null, DATA_VERSION, NO_STORAGE_NAMES, NO_STORAGE_NAME, NO_INCLUDE_ALL_REGISTERED_SUBPARTITIONS));
        fail("Suppose to throw an IllegalArgumentException when business object data registered in more than one storage.");
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Found business object data registered in more than one storage. " + "Please specify storage(s) in the request to resolve this. Business object data {%s}", businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataKeyAsString(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, MULTI_STORAGE_AVAILABLE_PARTITION_VALUES_INTERSECTION.get(0), SUBPARTITION_VALUES, DATA_VERSION)), e.getMessage());
    }
}
Also used : BusinessObjectDataAvailabilityRequest(org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityRequest) PartitionValueFilter(org.finra.herd.model.api.xml.PartitionValueFilter) Test(org.junit.Test)

Example 79 with PartitionValueFilter

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

the class BusinessObjectDataServiceCheckBusinessObjectDataAvailabilityTest method testCheckBusinessObjectDataAvailabilityLatestBeforePartitionValue.

@Test
public void testCheckBusinessObjectDataAvailabilityLatestBeforePartitionValue() {
    // Create database entities required for testing.
    storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, true, BusinessObjectDataStatusEntity.VALID, StorageUnitStatusEntity.ENABLED, NO_STORAGE_DIRECTORY_PATH);
    // Check an availability using a latest before partition value filter option.
    for (String upperBoundPartitionValue : Arrays.asList(PARTITION_VALUE, PARTITION_VALUE_2)) {
        BusinessObjectDataAvailability resultBusinessObjectDataAvailability = businessObjectDataService.checkBusinessObjectDataAvailability(new BusinessObjectDataAvailabilityRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, Arrays.asList(new PartitionValueFilter(PARTITION_KEY, NO_PARTITION_VALUES, NO_PARTITION_VALUE_RANGE, new LatestBeforePartitionValue(upperBoundPartitionValue), NO_LATEST_AFTER_PARTITION_VALUE)), null, DATA_VERSION, NO_STORAGE_NAMES, STORAGE_NAME, NO_INCLUDE_ALL_REGISTERED_SUBPARTITIONS));
        // Validate the response object.
        assertEquals(new BusinessObjectDataAvailability(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, Arrays.asList(new PartitionValueFilter(PARTITION_KEY, NO_PARTITION_VALUES, NO_PARTITION_VALUE_RANGE, new LatestBeforePartitionValue(upperBoundPartitionValue), NO_LATEST_AFTER_PARTITION_VALUE)), null, DATA_VERSION, NO_STORAGE_NAMES, STORAGE_NAME, Arrays.asList(new BusinessObjectDataStatus(FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, BusinessObjectDataStatusEntity.VALID)), new ArrayList<>()), resultBusinessObjectDataAvailability);
    }
}
Also used : BusinessObjectDataAvailabilityRequest(org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityRequest) LatestBeforePartitionValue(org.finra.herd.model.api.xml.LatestBeforePartitionValue) BusinessObjectDataAvailability(org.finra.herd.model.api.xml.BusinessObjectDataAvailability) ArrayList(java.util.ArrayList) BusinessObjectDataStatus(org.finra.herd.model.api.xml.BusinessObjectDataStatus) PartitionValueFilter(org.finra.herd.model.api.xml.PartitionValueFilter) Test(org.junit.Test)

Example 80 with PartitionValueFilter

use of org.finra.herd.model.api.xml.PartitionValueFilter 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)

Aggregations

PartitionValueFilter (org.finra.herd.model.api.xml.PartitionValueFilter)84 Test (org.junit.Test)72 ArrayList (java.util.ArrayList)40 BusinessObjectDataAvailabilityRequest (org.finra.herd.model.api.xml.BusinessObjectDataAvailabilityRequest)38 BusinessObjectDataDdlRequest (org.finra.herd.model.api.xml.BusinessObjectDataDdlRequest)32 BusinessObjectDataAvailability (org.finra.herd.model.api.xml.BusinessObjectDataAvailability)30 BusinessObjectDataStatus (org.finra.herd.model.api.xml.BusinessObjectDataStatus)27 BusinessObjectDataDdl (org.finra.herd.model.api.xml.BusinessObjectDataDdl)16 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)13 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)12 PartitionValueRange (org.finra.herd.model.api.xml.PartitionValueRange)12 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)10 LatestBeforePartitionValue (org.finra.herd.model.api.xml.LatestBeforePartitionValue)9 BusinessObjectDataSearchKey (org.finra.herd.model.api.xml.BusinessObjectDataSearchKey)8 LatestAfterPartitionValue (org.finra.herd.model.api.xml.LatestAfterPartitionValue)8 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)5 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)5 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)5 StorageEntity (org.finra.herd.model.jpa.StorageEntity)5 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)3