Search in sources :

Example 1 with InfinispanConnection

use of org.teiid.infinispan.api.InfinispanConnection in project teiid by teiid.

the class TestHotrodExecution method testServer.

@Test
public void testServer() throws Exception {
    InfinispanConnection connection = getConnection("default");
    CACHE_NAME = connection.getCache().getName();
    ResultSetExecution exec = null;
    Command command = null;
    UpdateExecution update = null;
    // the below also test one-2-one relation.
    command = UTILITY.parseCommand("DELETE FROM G2");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    command = UTILITY.parseCommand("SELECT e1, e2, g3_e1, g3_e2 FROM G2");
    exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
    exec.execute();
    assertNull(exec.next());
    command = UTILITY.parseCommand("INSERT INTO G2 (e1, e2, g3_e1, g3_e2) values (1, 'one', 1, 'one')");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    command = UTILITY.parseCommand("INSERT INTO G2 (e1, e2, g3_e1, g3_e2) values (2, 'two', 2, 'two')");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    command = UTILITY.parseCommand("SELECT e1, e2, g3_e1, g3_e2 FROM G2");
    exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
    exec.execute();
    assertArrayEquals(new Object[] { new Integer(1), "one", new Integer(1), "one" }, exec.next().toArray());
    assertArrayEquals(new Object[] { new Integer(2), "two", new Integer(2), "two" }, exec.next().toArray());
    assertNull(exec.next());
    command = UTILITY.parseCommand("INSERT INTO G4 (e1, e2, G2_e1) values (1, 'one', 1)");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    command = UTILITY.parseCommand("INSERT INTO G4 (e1, e2, G2_e1) values (2, 'one-one', 1)");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    command = UTILITY.parseCommand("INSERT INTO G4 (e1, e2, G2_e1) values (3, 'two', 2)");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    command = UTILITY.parseCommand("INSERT INTO G4 (e1, e2, G2_e1) values (4, 'two-two', 2)");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    command = UTILITY.parseCommand("SELECT e1, e2 FROM G4");
    exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
    exec.execute();
    assertArrayEquals(new Object[] { new Integer(1), "one" }, exec.next().toArray());
    assertArrayEquals(new Object[] { new Integer(2), "one-one" }, exec.next().toArray());
    assertArrayEquals(new Object[] { new Integer(3), "two" }, exec.next().toArray());
    assertArrayEquals(new Object[] { new Integer(4), "two-two" }, exec.next().toArray());
    assertNull(exec.next());
    command = UTILITY.parseCommand("SELECT g2.e1, g4.e1, g4.e2 FROM G2 g2 JOIN G4 g4 " + "ON g2.e1 = g4.G2_e1 WHERE g2.e2 = 'two'");
    exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
    exec.execute();
    assertArrayEquals(new Object[] { new Integer(2), new Integer(3), "two" }, exec.next().toArray());
    assertArrayEquals(new Object[] { new Integer(2), new Integer(4), "two-two" }, exec.next().toArray());
    assertNull(exec.next());
    // updates
    command = UTILITY.parseCommand("UPDATE G2 SET e2 = 'two-m', g3_e2 = 'two-mm' WHERE e1 = 2");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    command = UTILITY.parseCommand("SELECT e1, e2, g3_e1, g3_e2 FROM G2 ORDER BY e1");
    exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
    exec.execute();
    assertArrayEquals(new Object[] { new Integer(1), "one", new Integer(1), "one" }, exec.next().toArray());
    assertArrayEquals(new Object[] { new Integer(2), "two-m", new Integer(2), "two-mm" }, exec.next().toArray());
    assertNull(exec.next());
    // complex updates
    command = UTILITY.parseCommand("UPDATE G4 SET e2 = 'two-2' WHERE e2 = 'two-two' OR e2 = 'one-one'");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    command = UTILITY.parseCommand("SELECT e1, e2 FROM G4");
    exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
    exec.execute();
    assertArrayEquals(new Object[] { new Integer(1), "one" }, exec.next().toArray());
    assertArrayEquals(new Object[] { new Integer(2), "two-2" }, exec.next().toArray());
    assertArrayEquals(new Object[] { new Integer(3), "two" }, exec.next().toArray());
    assertArrayEquals(new Object[] { new Integer(4), "two-2" }, exec.next().toArray());
    assertNull(exec.next());
    // deletes
    command = UTILITY.parseCommand("DELETE FROM G4 where e2 = 'two-2'");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    command = UTILITY.parseCommand("SELECT e1, e2 FROM G4");
    exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
    exec.execute();
    assertArrayEquals(new Object[] { new Integer(1), "one" }, exec.next().toArray());
    assertArrayEquals(new Object[] { new Integer(3), "two" }, exec.next().toArray());
    assertNull(exec.next());
    command = UTILITY.parseCommand("DELETE FROM G2 where e1 = 1");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    command = UTILITY.parseCommand("SELECT * FROM G2");
    exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
    exec.execute();
    assertArrayEquals(new Object[] { new Integer(2), "two-m", new Integer(2), "two-mm", null, null }, exec.next().toArray());
    assertNull(exec.next());
    // upsert
    command = UTILITY.parseCommand("UPSERT INTO G2 (e1, e2, g3_e1, g3_e2) values (1, 'one', 1, 'one')");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    command = UTILITY.parseCommand("SELECT * FROM G2 order by e1");
    exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
    exec.execute();
    assertArrayEquals(new Object[] { new Integer(1), "one", new Integer(1), "one", null, null }, exec.next().toArray());
    assertArrayEquals(new Object[] { new Integer(2), "two-m", new Integer(2), "two-mm", null, null }, exec.next().toArray());
    assertNull(exec.next());
    command = UTILITY.parseCommand("UPSERT INTO G2 (e1, e2, g3_e1, g3_e2) values (2, 'two', 2, 'two')");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    command = UTILITY.parseCommand("SELECT * FROM G2");
    exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
    exec.execute();
    assertArrayEquals(new Object[] { new Integer(1), "one", new Integer(1), "one", null, null }, exec.next().toArray());
    assertArrayEquals(new Object[] { new Integer(2), "two", new Integer(2), "two", null, null }, exec.next().toArray());
    assertNull(exec.next());
    command = UTILITY.parseCommand("UPSERT INTO G4 (e1, e2, G2_e1) values (5, 'upsert', 2)");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    command = UTILITY.parseCommand("SELECT e1, e2 FROM G4");
    exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
    exec.execute();
    assertArrayEquals(new Object[] { new Integer(3), "two" }, exec.next().toArray());
    assertArrayEquals(new Object[] { new Integer(5), "upsert" }, exec.next().toArray());
    assertNull(exec.next());
    Timestamp timestamp = new Timestamp(1504889513361L);
    Date date = new Date(1504889513361L);
    Time time = new Time(1504889513361L);
    String sql = "UPSERT INTO G5 (e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18) " + "values (512, 'one', convert(512.34, double), 512.25, 256, 1, 't', 1504889513361, convert(123445656.12313, bigdecimal), " + "convert(1332434343, biginteger), " + "{t '" + new SimpleDateFormat("HH:mm:ss").format(time) + "'}, " + "{ts '" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp) + "'}, " + "{d '" + new SimpleDateFormat("yyyy-MM-dd").format(date) + "'}, " + "null, null, " + "convert('clob contents', clob), xmlparse(CONTENT '<a>foo</a>'), null)";
    System.out.println(sql);
    command = UTILITY.parseCommand(sql);
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    command = UTILITY.parseCommand("SELECT e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18 FROM G5");
    exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
    exec.execute();
    List<?> results = exec.next();
    assertEquals(new Integer(512), (Integer) results.get(0));
    assertEquals("one", (String) results.get(1));
    // assertEquals(512.34, (double)results.get(2));
    // assertEquals(512.25, (float)results.get(3));
    assertEquals(new Short("256"), results.get(4));
    assertEquals(new Byte("1"), results.get(5));
    assertEquals(new String("t"), results.get(6));
    assertEquals(new Long(1504889513361L), results.get(7));
    assertEquals(new BigDecimal("123445656.12313").toPlainString(), ((BigDecimal) results.get(8)).toPlainString());
    assertEquals(new BigInteger("1332434343").toString(), ((BigInteger) results.get(9)).toString());
    assertEquals(new Time(new SimpleDateFormat("HH:mm:ss").parse(time.toString()).getTime()), results.get(10));
    assertEquals(new Timestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2017-09-08 11:51:53").getTime()), results.get(11));
    assertEquals(new Date(new SimpleDateFormat("yyyy-MM-dd").parse("2017-09-08").getTime()), results.get(12));
    assertEquals("clob contents", ObjectConverterUtil.convertToString(((Clob) results.get(15)).getCharacterStream()));
    assertEquals("<a>foo</a>", ObjectConverterUtil.convertToString(((SQLXML) results.get(16)).getCharacterStream()));
    assertNull(exec.next());
}
Also used : UpdateExecution(org.teiid.translator.UpdateExecution) Time(java.sql.Time) Timestamp(java.sql.Timestamp) Date(java.sql.Date) BigDecimal(java.math.BigDecimal) BigInteger(java.math.BigInteger) ResultSetExecution(org.teiid.translator.ResultSetExecution) SQLXML(java.sql.SQLXML) Command(org.teiid.language.Command) InfinispanConnection(org.teiid.infinispan.api.InfinispanConnection) BigInteger(java.math.BigInteger) QueryExpression(org.teiid.language.QueryExpression) Clob(java.sql.Clob) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 2 with InfinispanConnection

use of org.teiid.infinispan.api.InfinispanConnection in project teiid by teiid.

the class TestHotrodExecution method setup.

@BeforeClass
public static void setup() throws Exception {
    TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("GMT-5"));
    SERVER = new HotRodTestServer(PORT);
    MetadataFactory mf = TestProtobufMetadataProcessor.protoMatadata("tables.proto");
    EF = new InfinispanExecutionFactory();
    TransformationMetadata tm = TestProtobufMetadataProcessor.getTransformationMetadata(mf, EF);
    // String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
    // System.out.println(ddl);
    METADATA = new RuntimeMetadataImpl(tm);
    UTILITY = new TranslationUtility(tm);
    InfinispanConnection connection = SERVER.getConnection();
    // only use G2 & G4 as cache only support single id
    connection.registerProtobufFile(new ProtobufResource("tables.proto", ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("tables.proto"))));
    EC = Mockito.mock(ExecutionContext.class);
    Mockito.stub(EC.getBatchSize()).toReturn(512);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) ExecutionContext(org.teiid.translator.ExecutionContext) MetadataFactory(org.teiid.metadata.MetadataFactory) RuntimeMetadataImpl(org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl) HotRodTestServer(org.teiid.infinispan.api.HotRodTestServer) TranslationUtility(org.teiid.cdk.api.TranslationUtility) InfinispanConnection(org.teiid.infinispan.api.InfinispanConnection) ProtobufResource(org.teiid.infinispan.api.ProtobufResource) BeforeClass(org.junit.BeforeClass)

Example 3 with InfinispanConnection

use of org.teiid.infinispan.api.InfinispanConnection in project teiid by teiid.

the class TestSchemaToProtobufProcessor method testConverstion.

@SuppressWarnings("rawtypes")
@Test
public void testConverstion() throws Exception {
    SchemaToProtobufProcessor tool = new SchemaToProtobufProcessor();
    // tool.setIndexMessages(true);
    MetadataFactory mf = TestProtobufMetadataProcessor.protoMatadata("tables.proto");
    InfinispanConnection conn = Mockito.mock(InfinispanConnection.class);
    BasicCache cache = Mockito.mock(BasicCache.class);
    Mockito.stub(cache.getName()).toReturn("default");
    Mockito.stub(conn.getCache()).toReturn(cache);
    ProtobufResource resource = tool.process(mf, conn);
    String expected = "package model;\n" + "\n" + "/* @Indexed @Cache(name=foo) */\n" + "message G1 {\n" + "    /* @Id @IndexedField(index=true, store=false) */\n" + "    required int32 e1 = 1;\n" + "    /* @IndexedField */\n" + "    required string e2 = 2;\n" + "    optional float e3 = 3;\n" + "    /* @IndexedField(index=true, store=false) */\n" + "    repeated string e4 = 4;\n" + "    repeated string e5 = 5;\n" + "}\n" + "\n" + "/* @Indexed */\n" + "message G2 {\n" + "    /* @Id */\n" + "    required int32 e1 = 1;\n" + "    required string e2 = 2;\n" + "    optional G3 g3 = 5;\n" + "    /* @IndexedField(index=false) */\n" + "    optional bytes e5 = 7;\n" + "    /* @Teiid(type=long) */\n" + "    optional fixed64 e6 = 8;\n" + "    repeated G4 g4 = 6;\n" + "}\n" + "\n" + "/* @Indexed */\n" + "message G4 {\n" + "    required int32 e1 = 1;\n" + "    required string e2 = 2;\n" + "    optional int32 e1 = 3;\n" + "}\n" + "\n" + "/* @Indexed */\n" + "message G5 {\n" + "    /* @Id */\n" + "    required int32 e1 = 1;\n" + "    required string e2 = 2;\n" + "    optional double e3 = 3;\n" + "    optional float e4 = 4;\n" + "    /* @Teiid(type=short) */\n" + "    optional int32 e5 = 5;\n" + "    /* @Teiid(type=byte) */\n" + "    optional int32 e6 = 6;\n" + "    /* @Teiid(type=char, length=1) */\n" + "    optional string e7 = 7;\n" + "    optional int64 e8 = 8;\n" + "    /* @Teiid(type=bigdecimal) */\n" + "    optional string e9 = 9;\n" + "    /* @Teiid(type=biginteger) */\n" + "    optional string e10 = 10;\n" + "    /* @Teiid(type=time) */\n" + "    optional int64 e11 = 11;\n" + "    /* @Teiid(type=timestamp) */\n" + "    optional int64 e12 = 12;\n" + "    /* @Teiid(type=date) */\n" + "    optional int64 e13 = 13;\n" + "    /* @Teiid(type=object) */\n" + "    optional bytes e14 = 14;\n" + "    /* @Teiid(type=blob) */\n" + "    optional bytes e15 = 15;\n" + "    /* @Teiid(type=clob) */\n" + "    optional bytes e16 = 16;\n" + "    /* @Teiid(type=xml) */\n" + "    optional bytes e17 = 17;\n" + "    /* @Teiid(type=geometry) */\n" + "    optional bytes e18 = 18;\n" + "}\n" + "\n" + "message pm1.G3 {\n" + "    required int32 e1 = 1;\n" + "    required string e2 = 2;\n" + "}";
    assertEquals(expected, resource.getContents());
}
Also used : MetadataFactory(org.teiid.metadata.MetadataFactory) BasicCache(org.infinispan.commons.api.BasicCache) InfinispanConnection(org.teiid.infinispan.api.InfinispanConnection) ProtobufResource(org.teiid.infinispan.api.ProtobufResource) Test(org.junit.Test)

Example 4 with InfinispanConnection

use of org.teiid.infinispan.api.InfinispanConnection in project teiid by teiid.

the class TestHotrodExecution method testServer_Teiid_5165.

// TEIID-5165 - test large cache delete
@Test
public void testServer_Teiid_5165() throws Exception {
    EF.setSupportsUpsert(false);
    ResultSetExecution exec = null;
    Command command = null;
    UpdateExecution update = null;
    InfinispanConnection connection = getConnection("foo");
    // the below also test one-2-one relation.
    command = UTILITY.parseCommand("DELETE FROM G2");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    int rows = 12000;
    for (int i = 0; i < rows; i++) {
        command = UTILITY.parseCommand("INSERT INTO G2 (e1, e2, g3_e1, g3_e2) values (" + i + ", 'row" + i + "', 1, 'one')");
        update = EF.createUpdateExecution(command, EC, METADATA, connection);
        update.execute();
    }
    Thread.sleep(5000);
    command = UTILITY.parseCommand("SELECT e1, e2 FROM G2");
    exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
    exec.execute();
    int cnt = 0;
    while (true) {
        List<?> results = exec.next();
        if (results == null)
            break;
        cnt++;
    }
    assertEquals(new Integer(rows), new Integer(cnt));
    command = UTILITY.parseCommand("DELETE FROM G2");
    update = EF.createUpdateExecution(command, EC, METADATA, connection);
    update.execute();
    command = UTILITY.parseCommand("SELECT count(*) as cnt FROM G2");
    exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
    exec.execute();
    assertNull(exec.next());
}
Also used : BigInteger(java.math.BigInteger) ResultSetExecution(org.teiid.translator.ResultSetExecution) Command(org.teiid.language.Command) InfinispanConnection(org.teiid.infinispan.api.InfinispanConnection) UpdateExecution(org.teiid.translator.UpdateExecution) QueryExpression(org.teiid.language.QueryExpression) Test(org.junit.Test)

Example 5 with InfinispanConnection

use of org.teiid.infinispan.api.InfinispanConnection in project teiid by teiid.

the class TestSchemaToProtobufProcessor method testConverstionUsingCacheAnnotation.

@SuppressWarnings("rawtypes")
@Test
public void testConverstionUsingCacheAnnotation() throws Exception {
    SchemaToProtobufProcessor tool = new SchemaToProtobufProcessor();
    tool.setIndexMessages(true);
    MetadataFactory mf = TestProtobufMetadataProcessor.protoMatadata("tables_bad.proto");
    InfinispanConnection conn = Mockito.mock(InfinispanConnection.class);
    BasicCache cache = Mockito.mock(BasicCache.class);
    Mockito.stub(cache.getName()).toReturn("foo");
    Mockito.stub(conn.getCache()).toReturn(cache);
    ProtobufResource resource = tool.process(mf, conn);
    String expected = "package model;\n" + "\n" + "/* @Indexed @Cache(name=foo) */\n" + "message G1 {\n" + "    /* @Id @IndexedField(index=true, store=false) */\n" + "    required int32 e1 = 1;\n" + "    /* @IndexedField */\n" + "    required string e2 = 2;\n" + "    optional float e3 = 3;\n" + "    /* @IndexedField(index=true, store=false) */\n" + "    repeated string e4 = 4;\n" + "    repeated string e5 = 5;\n" + "}\n\n";
    assertEquals(expected, resource.getContents());
}
Also used : MetadataFactory(org.teiid.metadata.MetadataFactory) BasicCache(org.infinispan.commons.api.BasicCache) InfinispanConnection(org.teiid.infinispan.api.InfinispanConnection) ProtobufResource(org.teiid.infinispan.api.ProtobufResource) Test(org.junit.Test)

Aggregations

InfinispanConnection (org.teiid.infinispan.api.InfinispanConnection)6 Test (org.junit.Test)5 ProtobufResource (org.teiid.infinispan.api.ProtobufResource)4 MetadataFactory (org.teiid.metadata.MetadataFactory)4 BasicCache (org.infinispan.commons.api.BasicCache)3 BigInteger (java.math.BigInteger)2 Command (org.teiid.language.Command)2 QueryExpression (org.teiid.language.QueryExpression)2 ResultSetExecution (org.teiid.translator.ResultSetExecution)2 UpdateExecution (org.teiid.translator.UpdateExecution)2 FileReader (java.io.FileReader)1 BigDecimal (java.math.BigDecimal)1 Clob (java.sql.Clob)1 Date (java.sql.Date)1 SQLXML (java.sql.SQLXML)1 Time (java.sql.Time)1 Timestamp (java.sql.Timestamp)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Properties (java.util.Properties)1 BeforeClass (org.junit.BeforeClass)1