Search in sources :

Example 1 with GoogleSpreadsheetConnection

use of org.teiid.translator.google.api.GoogleSpreadsheetConnection in project teiid by teiid.

the class TestMetadataProcessor method testRemoveColumns.

@Test
public void testRemoveColumns() throws Exception {
    GoogleSpreadsheetConnection conn = Mockito.mock(GoogleSpreadsheetConnection.class);
    SpreadsheetInfo people = new SpreadsheetInfo("People");
    Worksheet worksheet = people.createWorksheet("PeopleList");
    worksheet.setHeaderEnabled(true);
    for (int i = 1; i <= 3; i++) {
        Column newCol = new Column();
        newCol.setAlphaName(Util.convertColumnIDtoString(i));
        newCol.setLabel("c" + i);
        if (i == 1) {
            newCol.setDataType(SpreadsheetColumnType.DATETIME);
        }
        worksheet.addColumn(newCol.getAlphaName(), newCol);
    }
    Column newCol = new Column();
    newCol.setAlphaName("empty");
    worksheet.addColumn(null, newCol);
    Mockito.stub(conn.getSpreadsheetInfo()).toReturn(people);
    MetadataFactory factory = new MetadataFactory("", 1, "", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), "");
    GoogleMetadataProcessor processor = new GoogleMetadataProcessor();
    processor.process(factory, conn);
    Table t = factory.getSchema().getTables().get("PeopleList");
    assertTrue(t.supportsUpdate());
    assertEquals(3, t.getColumns().size());
    assertTrue(t.getColumns().get(0).isUpdatable());
    processor.setAllTypesUpdatable(false);
    factory = new MetadataFactory("", 1, "", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), "");
    processor.process(factory, conn);
    t = factory.getSchema().getTables().get("PeopleList");
    assertFalse(t.getColumns().get(0).isUpdatable());
}
Also used : Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) SpreadsheetInfo(org.teiid.translator.google.api.metadata.SpreadsheetInfo) Column(org.teiid.translator.google.api.metadata.Column) Worksheet(org.teiid.translator.google.api.metadata.Worksheet) Properties(java.util.Properties) GoogleSpreadsheetConnection(org.teiid.translator.google.api.GoogleSpreadsheetConnection) Test(org.junit.Test)

Example 2 with GoogleSpreadsheetConnection

use of org.teiid.translator.google.api.GoogleSpreadsheetConnection in project teiid by teiid.

the class TestNativeSpreadsheet method testDirect.

@Test
public void testDirect() throws TranslatorException {
    SpreadsheetExecutionFactory sef = new SpreadsheetExecutionFactory();
    sef.setSupportsDirectQueryProcedure(true);
    String input = "call native('worksheet=x;query=$1 foo;limit=2', 'a')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    GoogleSpreadsheetConnection connection = Mockito.mock(GoogleSpreadsheetConnection.class);
    RowsResult result = Mockito.mock(RowsResult.class);
    Mockito.stub(result.iterator()).toReturn(Arrays.asList(new SheetRow()).iterator());
    Mockito.stub(connection.executeQuery("x", "'a' foo", null, 2, 0)).toReturn(result);
    ResultSetExecution execution = (ResultSetExecution) sef.createExecution(command, ec, rm, connection);
    execution.execute();
    List<?> vals = execution.next();
    assertTrue(vals.get(0) instanceof Object[]);
}
Also used : TranslationUtility(org.teiid.cdk.api.TranslationUtility) RowsResult(org.teiid.translator.google.api.result.RowsResult) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) SheetRow(org.teiid.translator.google.api.result.SheetRow) Command(org.teiid.language.Command) GoogleSpreadsheetConnection(org.teiid.translator.google.api.GoogleSpreadsheetConnection) Test(org.junit.Test)

Example 3 with GoogleSpreadsheetConnection

use of org.teiid.translator.google.api.GoogleSpreadsheetConnection in project teiid by teiid.

the class TestSQLtoSpreadsheetQuery method dummySpreadsheetMetadata.

private QueryMetadataInterface dummySpreadsheetMetadata() throws Exception {
    GoogleSpreadsheetConnection conn = Mockito.mock(GoogleSpreadsheetConnection.class);
    Mockito.stub(conn.getSpreadsheetInfo()).toReturn(people);
    MetadataFactory factory = new MetadataFactory("", 1, "", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), "");
    GoogleMetadataProcessor processor = new GoogleMetadataProcessor();
    processor.process(factory, conn);
    return new TransformationMetadata(null, new CompositeMetadataStore(factory.asMetadataStore()), null, RealMetadataFactory.SFM.getSystemFunctions(), null);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Properties(java.util.Properties) GoogleSpreadsheetConnection(org.teiid.translator.google.api.GoogleSpreadsheetConnection)

Example 4 with GoogleSpreadsheetConnection

use of org.teiid.translator.google.api.GoogleSpreadsheetConnection in project teiid by teiid.

the class TestSQLtoSpreadsheetQuery method testInsertExecution.

@Test
public void testInsertExecution() throws Exception {
    String sql = "insert into PeopleList(A,B,C) values ('String,String', 'val', 15.5)";
    Insert insert = (Insert) getCommand(sql);
    GoogleSpreadsheetConnection gsc = Mockito.mock(GoogleSpreadsheetConnection.class);
    Mockito.stub(gsc.getSpreadsheetInfo()).toReturn(people);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    SpreadsheetUpdateExecution sue = new SpreadsheetUpdateExecution(insert, gsc, ec, rm);
    sue.execute();
    LinkedHashMap<String, Object> vals = new LinkedHashMap<String, Object>();
    vals.put("A", "String,String");
    vals.put("B", "val");
    vals.put("C", 15.5);
    Mockito.verify(gsc).executeRowInsert("PeopleList", vals);
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Insert(org.teiid.language.Insert) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) GoogleSpreadsheetConnection(org.teiid.translator.google.api.GoogleSpreadsheetConnection) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

GoogleSpreadsheetConnection (org.teiid.translator.google.api.GoogleSpreadsheetConnection)4 Test (org.junit.Test)3 Properties (java.util.Properties)2 MetadataFactory (org.teiid.metadata.MetadataFactory)2 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)2 ExecutionContext (org.teiid.translator.ExecutionContext)2 LinkedHashMap (java.util.LinkedHashMap)1 TranslationUtility (org.teiid.cdk.api.TranslationUtility)1 Command (org.teiid.language.Command)1 Insert (org.teiid.language.Insert)1 Table (org.teiid.metadata.Table)1 CompositeMetadataStore (org.teiid.query.metadata.CompositeMetadataStore)1 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)1 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)1 ResultSetExecution (org.teiid.translator.ResultSetExecution)1 Column (org.teiid.translator.google.api.metadata.Column)1 SpreadsheetInfo (org.teiid.translator.google.api.metadata.SpreadsheetInfo)1 Worksheet (org.teiid.translator.google.api.metadata.Worksheet)1 RowsResult (org.teiid.translator.google.api.result.RowsResult)1 SheetRow (org.teiid.translator.google.api.result.SheetRow)1