use of org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest in project herd by FINRAOS.
the class GenerateBusinessObjectFormatDdl method executeImpl.
@Override
public void executeImpl(DelegateExecution execution) throws Exception {
String namespace = activitiHelper.getExpressionVariableAsString(this.namespace, execution);
String businessObjectDefinitionName = activitiHelper.getExpressionVariableAsString(this.businessObjectDefinitionName, execution);
String businessObjectFormatUsage = activitiHelper.getExpressionVariableAsString(this.businessObjectFormatUsage, execution);
String businessObjectFormatFileType = activitiHelper.getExpressionVariableAsString(this.businessObjectFormatFileType, execution);
Integer businessObjectFormatVersion = activitiHelper.getExpressionVariableAsInteger(this.businessObjectFormatVersion, execution, "businessObjectFormatVersion", false);
String outputFormat = activitiHelper.getRequiredExpressionVariableAsString(this.outputFormat, execution, "outputFormat");
BusinessObjectDataDdlOutputFormatEnum outputFormatEnum = BusinessObjectDataDdlOutputFormatEnum.fromValue(outputFormat);
String tableName = activitiHelper.getExpressionVariableAsString(this.tableName, execution);
String customDdlName = activitiHelper.getExpressionVariableAsString(this.customDdlName, execution);
Boolean includeDropTableStatement = activitiHelper.getExpressionVariableAsBoolean(this.includeDropTableStatement, execution, "includeDropTableStatement", false, false);
Boolean includeIfNotExistsOption = activitiHelper.getExpressionVariableAsBoolean(this.includeIfNotExistsOption, execution, "includeIfNotExistsOption", false, false);
Boolean replaceColumns = activitiHelper.getExpressionVariableAsBoolean(this.replaceColumns, execution, "replaceColumns", false, false);
BusinessObjectFormatDdlRequest businessObjectFormatDdlRequest = new BusinessObjectFormatDdlRequest();
businessObjectFormatDdlRequest.setNamespace(namespace);
businessObjectFormatDdlRequest.setBusinessObjectDefinitionName(businessObjectDefinitionName);
businessObjectFormatDdlRequest.setBusinessObjectFormatUsage(businessObjectFormatUsage);
businessObjectFormatDdlRequest.setBusinessObjectFormatFileType(businessObjectFormatFileType);
businessObjectFormatDdlRequest.setBusinessObjectFormatVersion(businessObjectFormatVersion);
businessObjectFormatDdlRequest.setOutputFormat(outputFormatEnum);
businessObjectFormatDdlRequest.setTableName(tableName);
businessObjectFormatDdlRequest.setCustomDdlName(customDdlName);
businessObjectFormatDdlRequest.setIncludeDropTableStatement(includeDropTableStatement);
businessObjectFormatDdlRequest.setIncludeIfNotExistsOption(includeIfNotExistsOption);
businessObjectFormatDdlRequest.setReplaceColumns(replaceColumns);
BusinessObjectFormatDdl businessObjectFormatDdl = businessObjectFormatService.generateBusinessObjectFormatDdl(businessObjectFormatDdlRequest);
setTaskWorkflowVariable(execution, VARIABLE_DDL, businessObjectFormatDdl.getDdl());
}
use of org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest in project herd by FINRAOS.
the class BusinessObjectFormatServiceTest method testGenerateBusinessObjectFormatDdlNoCustomDdlForwardSlashInPartitionColumnName.
@Test
public void testGenerateBusinessObjectFormatDdlNoCustomDdlForwardSlashInPartitionColumnName() {
// Prepare test data without custom ddl.
String invalidPartitionColumnName = "INVALID_/_PRTN_CLMN";
List<SchemaColumn> partitionColumns = schemaColumnDaoTestHelper.getTestPartitionColumns();
partitionColumns.get(0).setName(invalidPartitionColumnName);
businessObjectFormatServiceTestHelper.createDatabaseEntitiesForBusinessObjectFormatDdlTesting(FileTypeEntity.TXT_FILE_TYPE, PARTITION_KEY, SCHEMA_DELIMITER_PIPE, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_NULL_VALUE_BACKSLASH_N, schemaColumnDaoTestHelper.getTestSchemaColumns(), partitionColumns, null);
// Try to retrieve business object format ddl for the format that uses unsupported schema column data type.
BusinessObjectFormatDdlRequest request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(null);
try {
businessObjectFormatService.generateBusinessObjectFormatDdl(request);
fail("Should throw an IllegalArgumentException when partition column name contains a '/' character.");
} catch (IllegalArgumentException e) {
assertEquals(String.format("Partition column name \"%s\" can not contain a '/' character. Business object format: " + "{namespace: \"%s\", businessObjectDefinitionName: \"%s\", businessObjectFormatUsage: \"%s\", " + "businessObjectFormatFileType: \"%s\", businessObjectFormatVersion: %d}", invalidPartitionColumnName, request.getNamespace(), request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion()), e.getMessage());
}
}
use of org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest in project herd by FINRAOS.
the class BusinessObjectFormatServiceTest method testGenerateBusinessObjectFormatDdlMissingRequiredParameters.
@Test
public void testGenerateBusinessObjectFormatDdlMissingRequiredParameters() {
BusinessObjectFormatDdlRequest request;
// Try to retrieve business object format ddl when namespace parameter is not specified.
request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
request.setNamespace(BLANK_TEXT);
try {
businessObjectFormatService.generateBusinessObjectFormatDdl(request);
fail("Should throw an IllegalArgumentException when namespace parameter is not specified.");
} catch (IllegalArgumentException e) {
assertEquals("A namespace must be specified.", e.getMessage());
}
// Try to retrieve business object format ddl when business object definition name parameter is not specified.
request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
request.setBusinessObjectDefinitionName(BLANK_TEXT);
try {
businessObjectFormatService.generateBusinessObjectFormatDdl(request);
fail("Should throw an IllegalArgumentException when business object definition name parameter is not specified.");
} catch (IllegalArgumentException e) {
assertEquals("A business object definition name must be specified.", e.getMessage());
}
// Try to retrieve business object format ddl when business object format usage parameter is not specified.
request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
request.setBusinessObjectFormatUsage(BLANK_TEXT);
try {
businessObjectFormatService.generateBusinessObjectFormatDdl(request);
fail("Should throw an IllegalArgumentException when business object format usage parameter is not specified.");
} catch (IllegalArgumentException e) {
assertEquals("A business object format usage must be specified.", e.getMessage());
}
// Try to retrieve business object format ddl when business object format file type parameter is not specified.
request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
request.setBusinessObjectFormatFileType(BLANK_TEXT);
try {
businessObjectFormatService.generateBusinessObjectFormatDdl(request);
fail("Should throw an IllegalArgumentException when business object format file type parameter is not specified.");
} catch (IllegalArgumentException e) {
assertEquals("A business object format file type must be specified.", e.getMessage());
}
// Try to retrieve business object format ddl when output format parameter is not specified.
request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
request.setOutputFormat(null);
try {
businessObjectFormatService.generateBusinessObjectFormatDdl(request);
fail("Should throw an IllegalArgumentException when output format parameter is not specified.");
} catch (IllegalArgumentException e) {
assertEquals("An output format must be specified.", e.getMessage());
}
// Try to retrieve business object format ddl when table name parameter is not specified.
request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
request.setTableName(BLANK_TEXT);
try {
businessObjectFormatService.generateBusinessObjectFormatDdl(request);
fail("Should throw an IllegalArgumentException when table name parameter is not specified.");
} catch (IllegalArgumentException e) {
assertEquals("A table name must be specified.", e.getMessage());
}
}
use of org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest in project herd by FINRAOS.
the class BusinessObjectFormatServiceTest method testGenerateBusinessObjectFormatDdlLowerCaseParameters.
@Test
public void testGenerateBusinessObjectFormatDdlLowerCaseParameters() {
// Prepare test data.
businessObjectFormatServiceTestHelper.createDatabaseEntitiesForBusinessObjectFormatDdlTesting();
// Retrieve business object format ddl request with all string values in lower case.
BusinessObjectFormatDdlRequest request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
request.setNamespace(request.getNamespace().toLowerCase());
request.setBusinessObjectDefinitionName(request.getBusinessObjectDefinitionName().toLowerCase());
request.setBusinessObjectFormatUsage(request.getBusinessObjectFormatUsage().toLowerCase());
request.setBusinessObjectFormatFileType(request.getBusinessObjectFormatFileType().toLowerCase());
request.setCustomDdlName(request.getCustomDdlName().toLowerCase());
BusinessObjectFormatDdl resultDdl = businessObjectFormatService.generateBusinessObjectFormatDdl(request);
// Validate the results.
businessObjectFormatServiceTestHelper.validateBusinessObjectFormatDdl(CUSTOM_DDL_NAME, businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatDdl(AbstractServiceTest.PARTITION_COLUMNS.length, AbstractServiceTest.FIRST_COLUMN_NAME, AbstractServiceTest.FIRST_COLUMN_DATA_TYPE, AbstractServiceTest.ROW_FORMAT, Hive13DdlGenerator.TEXT_HIVE_FILE_FORMAT, FileTypeEntity.TXT_FILE_TYPE, true, true), resultDdl);
}
use of org.finra.herd.model.api.xml.BusinessObjectFormatDdlRequest in project herd by FINRAOS.
the class BusinessObjectFormatServiceTest method testGenerateBusinessObjectFormatDdlWhenReplaceColumnsMissingOptionalParameters.
/**
* Asserts that when replace columns is TRUE and other optional parameters are not specified.
*/
@Test
public void testGenerateBusinessObjectFormatDdlWhenReplaceColumnsMissingOptionalParameters() {
businessObjectFormatServiceTestHelper.createDatabaseEntitiesForBusinessObjectFormatDdlTesting();
BusinessObjectFormatDdlRequest businessObjectFormatDdlRequest = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(null);
businessObjectFormatDdlRequest.setReplaceColumns(true);
businessObjectFormatDdlRequest.setIncludeDropTableStatement(null);
businessObjectFormatDdlRequest.setIncludeIfNotExistsOption(null);
BusinessObjectFormatDdl result = businessObjectFormatService.generateBusinessObjectFormatDdl(businessObjectFormatDdlRequest);
Assert.assertEquals("result DDL", result.getDdl(), "ALTER TABLE `" + businessObjectFormatDdlRequest.getTableName() + "` REPLACE COLUMNS (\n" + " `COLUMN001` TINYINT,\n" + " `COLUMN002` SMALLINT COMMENT 'This is \\'COLUMN002\\' column. Here are \\'single\\' and \"double\" quotes along with a backslash \\.',\n" + " `COLUMN003` INT,\n" + " `COLUMN004` BIGINT,\n" + " `COLUMN005` FLOAT,\n" + " `COLUMN006` DOUBLE,\n" + " `COLUMN007` DECIMAL,\n" + " `COLUMN008` DECIMAL(p,s),\n" + " `COLUMN009` DECIMAL,\n" + " `COLUMN010` DECIMAL(p),\n" + " `COLUMN011` DECIMAL(p,s),\n" + " `COLUMN012` TIMESTAMP,\n" + " `COLUMN013` DATE,\n" + " `COLUMN014` STRING,\n" + " `COLUMN015` VARCHAR(n),\n" + " `COLUMN016` VARCHAR(n),\n" + " `COLUMN017` CHAR(n),\n" + " `COLUMN018` BOOLEAN,\n" + " `COLUMN019` BINARY);");
}
Aggregations