Search in sources :

Example 1 with TdchConnectionService

use of com.thinkbiganalytics.kylo.nifi.teradata.tdch.api.TdchConnectionService in project kylo by Teradata.

the class TdchExportHiveToTeradataTest method testTeradataForceStage.

@Test
public void testTeradataForceStage() throws InitializationException {
    final TestRunner runner = TestRunners.newTestRunner(TdchExportHiveToTeradata.class);
    TdchConnectionService tdchConnectionService = new DummyTdchConnectionService();
    runner.addControllerService(CONNECTION_SERVICE_ID, tdchConnectionService);
    runner.assertValid(tdchConnectionService);
    runner.enableControllerService(tdchConnectionService);
    runner.setProperty(TdchExportHiveToTeradata.TDCH_CONNECTION_SERVICE, CONNECTION_SERVICE_ID);
    runner.setProperty(TdchExportHiveToTeradata.HIVE_DATABASE, "hive_db");
    runner.setProperty(TdchExportHiveToTeradata.HIVE_TABLE, "hive_table");
    runner.setProperty(TdchExportHiveToTeradata.TERADATA_DATABASE_TABLE, "teradata_db.teradata_table");
    runner.assertValid();
    Assert.assertEquals("false", runner.getProcessor().getPropertyDescriptor(TdchExportHiveToTeradata.TERADATA_FORCE_STAGE_NAME).getDefaultValue());
    Assert.assertFalse(runner.getProcessor().getPropertyDescriptor(TdchExportHiveToTeradata.TERADATA_FORCE_STAGE_NAME).isRequired());
    Assert.assertTrue(runner.getProcessor().getPropertyDescriptor(TdchExportHiveToTeradata.TERADATA_FORCE_STAGE_NAME).isExpressionLanguageSupported());
    ValidationResult result = runner.setProperty(TdchExportHiveToTeradata.TERADATA_FORCE_STAGE, "true");
    Assert.assertTrue(result.isValid());
    result = runner.setProperty(TdchExportHiveToTeradata.TERADATA_FORCE_STAGE, "");
    Assert.assertFalse(result.isValid());
    result = runner.setProperty(TdchExportHiveToTeradata.TERADATA_FORCE_STAGE, "not-boolean-value");
    Assert.assertFalse(result.isValid());
    runner.removeProperty(TdchExportHiveToTeradata.TERADATA_FORCE_STAGE);
    runner.assertValid();
}
Also used : DevTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DevTdchConnectionService) DummyTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DummyTdchConnectionService) TdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.api.TdchConnectionService) TestRunner(org.apache.nifi.util.TestRunner) DummyTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DummyTdchConnectionService) ValidationResult(org.apache.nifi.components.ValidationResult) Test(org.junit.Test)

Example 2 with TdchConnectionService

use of com.thinkbiganalytics.kylo.nifi.teradata.tdch.api.TdchConnectionService in project kylo by Teradata.

the class TdchExportHiveToTeradataTest method testHiveDatabase.

@Test
public void testHiveDatabase() throws InitializationException {
    final TestRunner runner = TestRunners.newTestRunner(TdchExportHiveToTeradata.class);
    TdchConnectionService tdchConnectionService = new DummyTdchConnectionService();
    runner.addControllerService(CONNECTION_SERVICE_ID, tdchConnectionService);
    runner.assertValid(tdchConnectionService);
    runner.enableControllerService(tdchConnectionService);
    runner.setProperty(TdchExportHiveToTeradata.TDCH_CONNECTION_SERVICE, CONNECTION_SERVICE_ID);
    runner.setProperty(TdchExportHiveToTeradata.HIVE_DATABASE, "hive_db");
    runner.setProperty(TdchExportHiveToTeradata.HIVE_TABLE, "hive_table");
    runner.setProperty(TdchExportHiveToTeradata.TERADATA_DATABASE_TABLE, "teradata_db.teradata_table");
    runner.assertValid();
    Assert.assertEquals(null, runner.getProcessor().getPropertyDescriptor(TdchExportHiveToTeradata.HIVE_DATABASE_NAME).getDefaultValue());
    Assert.assertTrue(runner.getProcessor().getPropertyDescriptor(TdchExportHiveToTeradata.HIVE_DATABASE_NAME).isRequired());
    Assert.assertTrue(runner.getProcessor().getPropertyDescriptor(TdchExportHiveToTeradata.HIVE_DATABASE_NAME).isExpressionLanguageSupported());
    ValidationResult result = runner.setProperty(TdchExportHiveToTeradata.HIVE_DATABASE, "source_hive_db");
    Assert.assertTrue(result.isValid());
    result = runner.setProperty(TdchExportHiveToTeradata.HIVE_DATABASE, "");
    Assert.assertFalse(result.isValid());
    result = runner.setProperty(TdchExportHiveToTeradata.HIVE_DATABASE, "hive_db");
    Assert.assertTrue(result.isValid());
    runner.assertValid();
    runner.removeProperty(TdchExportHiveToTeradata.HIVE_DATABASE);
    runner.assertNotValid();
}
Also used : DevTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DevTdchConnectionService) DummyTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DummyTdchConnectionService) TdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.api.TdchConnectionService) TestRunner(org.apache.nifi.util.TestRunner) DummyTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DummyTdchConnectionService) ValidationResult(org.apache.nifi.components.ValidationResult) Test(org.junit.Test)

Example 3 with TdchConnectionService

use of com.thinkbiganalytics.kylo.nifi.teradata.tdch.api.TdchConnectionService in project kylo by Teradata.

the class TdchExportHiveToTeradataTest method testTdchConnectionService.

@Test
public void testTdchConnectionService() throws InitializationException {
    final TestRunner runner = TestRunners.newTestRunner(TdchExportHiveToTeradata.class);
    runner.assertNotValid();
    TdchConnectionService tdchConnectionService = new DummyTdchConnectionService();
    runner.addControllerService(CONNECTION_SERVICE_ID, tdchConnectionService);
    runner.assertNotValid();
    runner.setProperty(TdchExportHiveToTeradata.TDCH_CONNECTION_SERVICE, CONNECTION_SERVICE_ID);
    runner.assertNotValid();
    runner.enableControllerService(tdchConnectionService);
    runner.setProperty(TdchExportHiveToTeradata.HIVE_DATABASE, "hive_db");
    runner.setProperty(TdchExportHiveToTeradata.HIVE_TABLE, "hive_table");
    runner.setProperty(TdchExportHiveToTeradata.TERADATA_DATABASE_TABLE, "teradata_db.teradata_table");
    runner.assertValid();
}
Also used : DevTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DevTdchConnectionService) DummyTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DummyTdchConnectionService) TdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.api.TdchConnectionService) TestRunner(org.apache.nifi.util.TestRunner) DummyTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DummyTdchConnectionService) Test(org.junit.Test)

Example 4 with TdchConnectionService

use of com.thinkbiganalytics.kylo.nifi.teradata.tdch.api.TdchConnectionService in project kylo by Teradata.

the class TdchExportHiveToTeradataTest method testExport_HiveTextToTeradataBatchInsert_5_6_WithExpressions.

@Test
public void testExport_HiveTextToTeradataBatchInsert_5_6_WithExpressions() throws InitializationException {
    /*
        From actual run:
        Key: 'tdch.export.hive.to.teradata.command'
	Value: 'hadoop jar $USERLIBTDCH com.teradata.connector.common.tool.ConnectorExportTool -libjars $LIB_JARS -Dtdch.output.teradata.truncate=false -classname "com.teradata.jdbc.TeraDriver" -url "jdbc:teradata://localhost/database=finance" -username "dbc" -password ***** -method "batch.insert" -jobtype "hive" -fileformat "textfile" -nummappers "2" -throttlemappers "false" -sourcedateformat "yyyy-MM-dd" -sourcetimeformat "HH:mm:ss" -sourcetimestampformat "yyyy-MM-dd HH:mm:ss.SSS" -targetdateformat "yyyy-MM-dd" -targettimeformat "HH:mm:ss" -targettimestampformat "yyyy-MM-dd HH:mm:ss.SSS" -stringtruncate "true" -sourcedatabase "tdch" -sourcetable "example5_hive" -targettable "finance.example5_td" -usexviews "false" -batchsize "10000" -forcestage "false" -keepstagetable "false" '
        */
    final TestRunner runner = TestRunners.newTestRunner(TdchExportHiveToTeradata.class);
    TdchConnectionService tdchConnectionService = new DevTdchConnectionService();
    runner.addControllerService(CONNECTION_SERVICE_ID, tdchConnectionService);
    runner.assertValid(tdchConnectionService);
    runner.enableControllerService(tdchConnectionService);
    runner.setProperty(TdchExportHiveToTeradata.HIVE_DATABASE, "${hive_db}");
    runner.setProperty(TdchExportHiveToTeradata.HIVE_TABLE, "${hive_table}");
    runner.setProperty(TdchExportHiveToTeradata.TDCH_CONNECTION_SERVICE, CONNECTION_SERVICE_ID);
    runner.setProperty(TdchExportHiveToTeradata.TERADATA_DATABASE_TABLE, "${teradata_db}.${teradata_table}");
    runner.assertValid();
    runner.setProperty(TdchExportHiveToTeradata.HIVE_EXPORT_TOOL_JOB_TYPE, "${my.custom.var.export.tool.job.type}");
    runner.assertNotValid();
    runner.setProperty(TdchExportHiveToTeradata.HIVE_EXPORT_TOOL_JOB_TYPE, "${tdch.export.tool.job.type}");
    runner.assertValid();
    runner.setProperty(TdchExportHiveToTeradata.HIVE_EXPORT_TOOL_FILEFORMAT, "${my.custom.var.export.tool.file.format}");
    runner.assertNotValid();
    runner.setProperty(TdchExportHiveToTeradata.HIVE_EXPORT_TOOL_FILEFORMAT, "${tdch.export.tool.file.format}");
    runner.assertValid();
    MockFlowFile mockFlowFile = new MockFlowFile(1L);
    Map<String, String> attributes = new HashMap<>();
    attributes.put("tdch.export.tool.job.type", "hive");
    attributes.put("tdch.export.tool.file.format", "textfile");
    attributes.put("hive_db", "tdch");
    attributes.put("hive_table", "example5_hive");
    attributes.put("teradata_db", "finance");
    attributes.put("teradata_table", "example5_td");
    mockFlowFile.putAttributes(attributes);
    runner.enqueue(mockFlowFile);
    runner.run(1);
    List<MockFlowFile> failedFlowFiles = runner.getFlowFilesForRelationship(TdchExportHiveToTeradata.REL_FAILURE);
    Assert.assertEquals(1, failedFlowFiles.size());
    runner.assertQueueEmpty();
    String expectedCommand = "hadoop jar $USERLIBTDCH com.teradata.connector.common.tool.ConnectorExportTool -libjars $LIB_JARS -Dtdch.output.teradata.truncate=false -classname \"com.teradata.jdbc.TeraDriver\" -url \"jdbc:teradata://localhost/database=finance\" -username \"dbc\" -password ***** -method \"batch.insert\" -jobtype \"hive\" -fileformat \"textfile\" -nummappers \"2\" -throttlemappers \"false\" -sourcedateformat \"yyyy-MM-dd\" -sourcetimeformat \"HH:mm:ss\" -sourcetimestampformat \"yyyy-MM-dd HH:mm:ss.SSS\" -targetdateformat \"yyyy-MM-dd\" -targettimeformat \"HH:mm:ss\" -targettimestampformat \"yyyy-MM-dd HH:mm:ss.SSS\" -stringtruncate \"true\" -sourcedatabase \"tdch\" -sourcetable \"example5_hive\" -targettable \"finance.example5_td\" -usexviews \"false\" -batchsize \"10000\" -forcestage \"false\" -keepstagetable \"false\" ";
    MockFlowFile failedFlowFile = failedFlowFiles.get(0);
    Assert.assertEquals(expectedCommand, failedFlowFile.getAttribute("tdch.export.hive.to.teradata.command"));
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) DevTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DevTdchConnectionService) DummyTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DummyTdchConnectionService) TdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.api.TdchConnectionService) HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) DevTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DevTdchConnectionService) Test(org.junit.Test)

Example 5 with TdchConnectionService

use of com.thinkbiganalytics.kylo.nifi.teradata.tdch.api.TdchConnectionService in project kylo by Teradata.

the class TdchExportHiveToTeradataTest method testTeradataFieldNames.

@Test
public void testTeradataFieldNames() throws InitializationException {
    final TestRunner runner = TestRunners.newTestRunner(TdchExportHiveToTeradata.class);
    TdchConnectionService tdchConnectionService = new DummyTdchConnectionService();
    runner.addControllerService(CONNECTION_SERVICE_ID, tdchConnectionService);
    runner.assertValid(tdchConnectionService);
    runner.enableControllerService(tdchConnectionService);
    runner.setProperty(TdchExportHiveToTeradata.TDCH_CONNECTION_SERVICE, CONNECTION_SERVICE_ID);
    runner.setProperty(TdchExportHiveToTeradata.HIVE_DATABASE, "hive_db");
    runner.setProperty(TdchExportHiveToTeradata.HIVE_TABLE, "hive_table");
    runner.setProperty(TdchExportHiveToTeradata.TERADATA_DATABASE_TABLE, "teradata_db.teradata_table");
    runner.assertValid();
    Assert.assertNull(runner.getProcessor().getPropertyDescriptor(TdchExportHiveToTeradata.TERADATA_FIELD_NAMES_NAME).getDefaultValue());
    Assert.assertFalse(runner.getProcessor().getPropertyDescriptor(TdchExportHiveToTeradata.TERADATA_FIELD_NAMES_NAME).isRequired());
    Assert.assertTrue(runner.getProcessor().getPropertyDescriptor(TdchExportHiveToTeradata.TERADATA_FIELD_NAMES_NAME).isExpressionLanguageSupported());
    ValidationResult result = runner.setProperty(TdchExportHiveToTeradata.TERADATA_FIELD_NAMES, "td_field1,td_field2,td_field3");
    Assert.assertTrue(result.isValid());
    runner.assertNotValid();
    ValidationResult result2 = runner.setProperty(TdchExportHiveToTeradata.HIVE_FIELD_NAMES, "hv_field1,hv_field2");
    Assert.assertTrue(result2.isValid());
    runner.assertNotValid();
    result2 = runner.setProperty(TdchExportHiveToTeradata.HIVE_FIELD_NAMES, "hv_field1,hv_field2,hv_field3");
    Assert.assertTrue(result2.isValid());
    runner.assertValid();
    result = runner.setProperty(TdchExportHiveToTeradata.TERADATA_FIELD_NAMES, "");
    Assert.assertFalse(result.isValid());
    runner.assertNotValid();
    runner.removeProperty(TdchExportHiveToTeradata.TERADATA_FIELD_NAMES);
    runner.assertNotValid();
    runner.removeProperty(TdchExportHiveToTeradata.HIVE_FIELD_NAMES);
    runner.assertValid();
}
Also used : DevTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DevTdchConnectionService) DummyTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DummyTdchConnectionService) TdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.api.TdchConnectionService) TestRunner(org.apache.nifi.util.TestRunner) DummyTdchConnectionService(com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DummyTdchConnectionService) ValidationResult(org.apache.nifi.components.ValidationResult) Test(org.junit.Test)

Aggregations

TdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.api.TdchConnectionService)34 TestRunner (org.apache.nifi.util.TestRunner)33 Test (org.junit.Test)33 DevTdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DevTdchConnectionService)27 DummyTdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DummyTdchConnectionService)27 ValidationResult (org.apache.nifi.components.ValidationResult)23 HashMap (java.util.HashMap)8 MockFlowFile (org.apache.nifi.util.MockFlowFile)8 KerberosConfig (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.common.KerberosConfig)1 StandardTdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.StandardTdchConnectionService)1 TdchProcessResult (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.processor.base.TdchProcessResult)1 TdchProcessRunner (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.processor.base.TdchProcessRunner)1 TdchBuilder (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.processor.export.utils.TdchBuilder)1 TdchUtils (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.processor.export.utils.TdchUtils)1 ArrayList (java.util.ArrayList)1 FlowFile (org.apache.nifi.flowfile.FlowFile)1 ComponentLog (org.apache.nifi.logging.ComponentLog)1 StopWatch (org.apache.nifi.util.StopWatch)1