Search in sources :

Example 6 with MySQLDatabaseMeta

use of org.pentaho.di.core.database.MySQLDatabaseMeta in project pentaho-kettle by pentaho.

the class MySQLBulkLoaderTest method setUp.

@Before
public void setUp() {
    TransMeta transMeta = new TransMeta();
    transMeta.setName("MysqlBulkLoader");
    Map<String, String> vars = new HashMap<String, String>();
    vars.put("delim", ",");
    vars.put("enclos", "'");
    vars.put("charset", "UTF8");
    vars.put("tbl", "sometable");
    vars.put("schema", "someschema");
    transMeta.injectVariables(vars);
    MySQLDatabaseMeta mysql = new MySQLDatabaseMeta();
    mysql.setName("MySQL");
    DatabaseMeta dbMeta = new DatabaseMeta();
    dbMeta.setDatabaseInterface(mysql);
    dbMeta.setQuoteAllFields(true);
    lmeta = new MySQLBulkLoaderMeta();
    lmeta.setDelimiter("${delim}");
    lmeta.setEnclosure("${enclos}");
    lmeta.setEncoding("${charset}");
    lmeta.setTableName("${tbl}");
    lmeta.setSchemaName("${schema}");
    lmeta.setDatabaseMeta(dbMeta);
    ldata = new MySQLBulkLoaderData();
    PluginRegistry plugReg = PluginRegistry.getInstance();
    String mblPid = plugReg.getPluginId(StepPluginType.class, lmeta);
    smeta = new StepMeta(mblPid, "MySqlBulkLoader", lmeta);
    Trans trans = new Trans(transMeta);
    transMeta.addStep(smeta);
    lder = new MySQLBulkLoader(smeta, ldata, 1, transMeta, trans);
    lder.copyVariablesFrom(transMeta);
}
Also used : HashMap(java.util.HashMap) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransMeta(org.pentaho.di.trans.TransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) Before(org.junit.Before)

Example 7 with MySQLDatabaseMeta

use of org.pentaho.di.core.database.MySQLDatabaseMeta in project pentaho-kettle by pentaho.

the class DatabaseLookupUTest method testEqualsAndIsNullAreCached.

@Test
public void testEqualsAndIsNullAreCached() throws Exception {
    when(mockHelper.logChannelInterfaceFactory.create(any(), any(LoggingObjectInterface.class))).thenReturn(mockHelper.logChannelInterface);
    DatabaseLookup look = new MockDatabaseLookup(mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans);
    DatabaseLookupData lookData = new DatabaseLookupData();
    lookData.cache = DefaultCache.newCache(lookData, 0);
    lookData.lookupMeta = new RowMeta();
    MySQLDatabaseMeta mysql = new MySQLDatabaseMeta();
    mysql.setName("MySQL");
    DatabaseMeta dbMeta = new DatabaseMeta();
    dbMeta.setDatabaseInterface(mysql);
    DatabaseLookupMeta meta = new DatabaseLookupMeta();
    meta.setDatabaseMeta(dbMeta);
    meta.setTablename("VirtualTable");
    meta.setTableKeyField(new String[] { "ID1", "ID2" });
    meta.setKeyCondition(new String[] { "=", "IS NULL" });
    meta.setReturnValueNewName(new String[] { "val1", "val2" });
    meta.setReturnValueField(new String[] { BINARY_FIELD, BINARY_FIELD });
    meta.setReturnValueDefaultType(new int[] { ValueMetaInterface.TYPE_BINARY, ValueMetaInterface.TYPE_BINARY });
    meta.setStreamKeyField1(new String[0]);
    meta.setStreamKeyField2(new String[0]);
    meta.setReturnValueDefault(new String[] { "", "" });
    meta = spy(meta);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            RowMetaInterface row = (RowMetaInterface) invocation.getArguments()[0];
            ValueMetaInterface v = new ValueMetaBinary(BINARY_FIELD);
            row.addValueMeta(v);
            return null;
        }
    }).when(meta).getFields(any(RowMetaInterface.class), anyString(), any(RowMetaInterface[].class), any(StepMeta.class), any(VariableSpace.class), any(Repository.class), any(IMetaStore.class));
    look.init(meta, lookData);
    // Test for fix on PDI-15202
    assertTrue(lookData.allEquals);
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) VariableSpace(org.pentaho.di.core.variables.VariableSpace) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) ValueMetaBinary(org.pentaho.di.core.row.value.ValueMetaBinary) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) Repository(org.pentaho.di.repository.Repository) InvocationOnMock(org.mockito.invocation.InvocationOnMock) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) Test(org.junit.Test)

Aggregations

DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)7 MySQLDatabaseMeta (org.pentaho.di.core.database.MySQLDatabaseMeta)7 Test (org.junit.Test)5 DatabaseInterface (org.pentaho.di.core.database.DatabaseInterface)4 MariaDBDatabaseMeta (org.pentaho.di.core.database.MariaDBDatabaseMeta)3 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)3 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)3 StepMeta (org.pentaho.di.trans.step.StepMeta)3 PacketTooBigException (com.mysql.jdbc.PacketTooBigException)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)2 VariableSpace (org.pentaho.di.core.variables.VariableSpace)2 Repository (org.pentaho.di.repository.Repository)2 IMetaStore (org.pentaho.metastore.api.IMetaStore)2 MysqlDataTruncation (com.mysql.jdbc.MysqlDataTruncation)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1