use of org.teiid.translator.FileConnection in project teiid by teiid.
the class TestExcelExecution method testExecutionNE.
@Test
public void testExecutionNE() throws Exception {
FileConnection connection = Mockito.mock(FileConnection.class);
Mockito.stub(connection.getFile("names.xls")).toReturn(UnitTestUtil.getTestDataFile("names.xls"));
ArrayList results = helpExecute(commonDDL, connection, "select FirstName from Sheet1 WHERE ROW_ID != 16");
assertEquals("[[John], [Jane], [Sarah], [Rocky], [Total]]", results.toString());
}
use of org.teiid.translator.FileConnection in project teiid by teiid.
the class TestExcelExecution method testExecutionLT.
@Test
public void testExecutionLT() throws Exception {
FileConnection connection = Mockito.mock(FileConnection.class);
Mockito.stub(connection.getFile("names.xls")).toReturn(UnitTestUtil.getTestDataFile("names.xls"));
ArrayList results = helpExecute(commonDDL, connection, "select FirstName from Sheet1 WHERE ROW_ID < 16");
assertEquals("[[John], [Jane]]", results.toString());
}
use of org.teiid.translator.FileConnection in project teiid by teiid.
the class TestExcelExecution method testExecutionWithDataNumberWithHeaderXLS.
@Test
public void testExecutionWithDataNumberWithHeaderXLS() throws Exception {
String ddl = "CREATE FOREIGN TABLE Sheet1 (\n" + " ROW_ID integer OPTIONS (SEARCHABLE 'All_Except_Like', \"teiid_excel:CELL_NUMBER\" 'ROW_ID'),\n" + " FirstName string OPTIONS (SEARCHABLE 'Unsearchable', \"teiid_excel:CELL_NUMBER\" '7'),\n" + " LastName string OPTIONS (SEARCHABLE 'Unsearchable', \"teiid_excel:CELL_NUMBER\" '8'),\n" + " Age double OPTIONS (SEARCHABLE 'Unsearchable', \"teiid_excel:CELL_NUMBER\" '9'),\n" + " CONSTRAINT PK0 PRIMARY KEY(ROW_ID)\n" + ") OPTIONS (\"teiid_excel:FILE\" 'names.xls', \"teiid_excel:FIRST_DATA_ROW_NUMBER\" '18');";
FileConnection connection = Mockito.mock(FileConnection.class);
Mockito.stub(connection.getFile("names.xls")).toReturn(UnitTestUtil.getTestDataFile("names.xls"));
ArrayList results = helpExecute(ddl, connection, "select * from Sheet1");
assertEquals("[[18, Rocky, Dog, 3.0], [19, Total, null, 110.0]]", results.toString());
}
use of org.teiid.translator.FileConnection in project teiid by teiid.
the class TestExcelExecution method testExecutionNoDataNumberXLS.
@Test
public void testExecutionNoDataNumberXLS() throws Exception {
String ddl = "CREATE FOREIGN TABLE Sheet1 (\n" + " ROW_ID integer OPTIONS (SEARCHABLE 'All_Except_Like', \"teiid_excel:CELL_NUMBER\" 'ROW_ID'),\n" + " column1 string OPTIONS (SEARCHABLE 'Unsearchable', \"teiid_excel:CELL_NUMBER\" '7'),\n" + " column2 string OPTIONS (SEARCHABLE 'Unsearchable', \"teiid_excel:CELL_NUMBER\" '8'),\n" + " column3 string OPTIONS (SEARCHABLE 'Unsearchable', \"teiid_excel:CELL_NUMBER\" '9'),\n" + " CONSTRAINT PK0 PRIMARY KEY(ROW_ID)\n" + ") OPTIONS (\"teiid_excel:FILE\" 'names.xls');";
FileConnection connection = Mockito.mock(FileConnection.class);
Mockito.stub(connection.getFile("names.xls")).toReturn(UnitTestUtil.getTestDataFile("names.xls"));
ArrayList results = helpExecute(ddl, connection, "select * from Sheet1");
assertEquals("[[13, FirstName, LastName, Age], [14, John, Doe, 44.0], [15, Jane, Smith, 40.0], [16, Matt, Liek, 13.0], [17, Sarah, Byne, 10.0], [18, Rocky, Dog, 3.0], [19, Total, null, 110.0]]", results.toString());
}
use of org.teiid.translator.FileConnection in project teiid by teiid.
the class TestExcelExecution method testTime.
@Test
public void testTime() throws Exception {
FileConnection connection = Mockito.mock(FileConnection.class);
Mockito.stub(connection.getFile("names.xls")).toReturn(UnitTestUtil.getTestDataFile("names.xlsx"));
ArrayList results = helpExecute(commonDDL, connection, "select \"time\" from Sheet1");
// typed as time
assertEquals("[[10:12:14]]", results.toString());
String ddl = commonDDL.replace("\"time\" time", "\"time\" string");
results = helpExecute(ddl, connection, "select \"time\" from Sheet1", true);
// typed as string with formatting - Excel format
assertEquals("[[10:12:14 AM]]", results.toString());
// $NON-NLS-1$
TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("America/New_York"));
try {
results = helpExecute(ddl, connection, "select \"time\" from Sheet1", false);
// typed as string without formatting - SQL / Teiid format
// note this seems like an issue with poi - if the sheet is not using 1904 dates, then it will start the calendar at the 0 day, not the first.
// however this behavior is slightly better than the previous, which would have shown the numeric value instead
assertEquals("[[1899-12-31 10:12:14.0]]", results.toString());
} finally {
TimestampWithTimezone.resetCalendar(null);
}
}
Aggregations