use of org.teiid.metadata.Table in project teiid by teiid.
the class ExcelMetadataProcessor method addTable.
private void addTable(MetadataFactory mf, Sheet sheet, String xlsName, String originalName) {
int firstRowNumber = sheet.getFirstRowNum();
Row headerRow = null;
int firstCellNumber = -1;
if (this.hasHeader) {
headerRow = sheet.getRow(this.headerRowNumber);
if (headerRow != null) {
firstRowNumber = this.headerRowNumber;
firstCellNumber = headerRow.getFirstCellNum();
if (firstCellNumber == -1) {
LogManager.logInfo(LogConstants.CTX_CONNECTOR, ExcelPlugin.Util.gs(ExcelPlugin.Event.TEIID23006, xlsName));
return;
}
}
}
if (headerRow == null) {
while (firstCellNumber == -1) {
headerRow = sheet.getRow(firstRowNumber++);
// check if this is a empty sheet; the data must be present in first 10000 rows
if (headerRow == null && firstRowNumber > 10000) {
return;
}
if (headerRow == null) {
continue;
}
firstCellNumber = headerRow.getFirstCellNum();
}
}
// create a table for each sheet
AtomicInteger columnCount = new AtomicInteger();
Table table = mf.addTable(sheet.getSheetName());
table.setNameInSource(sheet.getSheetName());
table.setProperty(ExcelMetadataProcessor.FILE, originalName);
// add implicit row_id column based on row number from excel sheet
Column column = mf.addColumn(ROW_ID, TypeFacility.RUNTIME_NAMES.INTEGER, table);
column.setSearchType(SearchType.All_Except_Like);
column.setProperty(CELL_NUMBER, ROW_ID);
// $NON-NLS-1$
mf.addPrimaryKey("PK0", Arrays.asList(ROW_ID), table);
column.setUpdatable(false);
Row dataRow = null;
int lastCellNumber = headerRow.getLastCellNum();
// then only count cells that have a non-empty value.
if (this.hasHeader && !getIgnoreEmptyHeaderCells()) {
int cellCounter = 0;
for (int i = firstCellNumber; i < lastCellNumber; i++) {
Cell headerCell = headerRow.getCell(i);
if (isCellEmpty(headerCell)) {
// found a cell with no column name that will be the last cell.
break;
}
cellCounter++;
}
lastCellNumber = cellCounter + firstCellNumber;
}
if (this.hasDataRowNumber) {
// adjust for zero index
table.setProperty(ExcelMetadataProcessor.FIRST_DATA_ROW_NUMBER, String.valueOf(this.dataRowNumber + 1));
dataRow = sheet.getRow(this.dataRowNumber);
} else if (this.hasHeader) {
// +1 zero based, +1 to skip header
table.setProperty(ExcelMetadataProcessor.FIRST_DATA_ROW_NUMBER, String.valueOf(firstRowNumber + 2));
dataRow = sheet.getRow(firstRowNumber + 1);
} else {
// +1 already occurred because of the increment above
table.setProperty(ExcelMetadataProcessor.FIRST_DATA_ROW_NUMBER, String.valueOf(firstRowNumber));
dataRow = sheet.getRow(firstRowNumber);
}
if (firstCellNumber != -1) {
for (int j = firstCellNumber; j < lastCellNumber; j++) {
Cell headerCell = headerRow.getCell(j);
// cell has a value, if not move on to the next column in the sheet.
if (this.hasHeader && getIgnoreEmptyHeaderCells() && isCellEmpty(headerCell)) {
continue;
}
Cell dataCell = dataRow.getCell(j);
// if the cell value is null; then advance the data row cursor to to find it
if (dataCell == null) {
for (int rowNo = firstRowNumber + 1; rowNo < firstRowNumber + 10000; rowNo++) {
Row row = sheet.getRow(rowNo);
dataCell = row.getCell(j);
if (dataCell != null) {
break;
}
}
}
column = mf.addColumn(cellName(headerCell, columnCount), cellType(headerCell, dataCell), table);
column.setSearchType(SearchType.Unsearchable);
column.setProperty(ExcelMetadataProcessor.CELL_NUMBER, String.valueOf(j + 1));
}
}
}
use of org.teiid.metadata.Table 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());
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class TestVisitor method queryMetadataInterface.
private static TransformationMetadata queryMetadataInterface() {
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("couchbase");
CouchbaseMetadataProcessor mp = new CouchbaseMetadataProcessor();
MetadataFactory mf = new MetadataFactory("couchbase", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
Table customer = createTable(mf, KEYSPACE, "Customer");
mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, formCustomer(), mf, customer, customer.getName(), false, new Dimension());
Table order = createTable(mf, KEYSPACE, "Oder");
mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, formOder(), mf, order, order.getName(), false, new Dimension());
Table t2 = createTable(mf, "T2", "T2");
mp.scanRow("T2", "`T2`", formDataTypeJson(), mf, t2, t2.getName(), false, new Dimension());
Table t3 = createTable(mf, "T3", "T3");
mp.scanRow("T3", "`T3`", nestedJson(), mf, t3, t3.getName(), false, new Dimension());
mp.scanRow("T3", "`T3`", nestedArray(), mf, t3, t3.getName(), false, new Dimension());
mp.addProcedures(mf, null);
TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x");
ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
return tm;
} catch (MetadataException e) {
throw new RuntimeException(e);
}
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class DataTierTupleSource method checkForUpdates.
private void checkForUpdates(AtomicResultsMessage results, Command command, EventDistributor distributor, int commandIndex, long ts) {
if (!RelationalNodeUtil.isUpdate(command) || !(command instanceof ProcedureContainer)) {
return;
}
ProcedureContainer pc = (ProcedureContainer) command;
GroupSymbol gs = pc.getGroup();
Integer zero = Integer.valueOf(0);
if (results.getResults().length <= commandIndex || zero.equals(results.getResults()[commandIndex].get(0))) {
return;
}
Object metadataId = gs.getMetadataID();
if (metadataId == null) {
return;
}
if (!(metadataId instanceof Table)) {
if (metadataId instanceof TempMetadataID) {
TempMetadataID tid = (TempMetadataID) metadataId;
if (tid.getTableData().getModel() != null) {
tid.getTableData().dataModified((Integer) results.getResults()[commandIndex].get(0));
}
}
return;
}
Table t = (Table) metadataId;
t.setLastDataModification(ts);
if (distributor != null) {
distributor.dataModification(this.workItem.getDqpWorkContext().getVdbName(), this.workItem.getDqpWorkContext().getVdbVersion(), t.getParent().getName(), t.getName());
}
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class TestProcessor method createProjectErrorMetadata.
private TransformationMetadata createProjectErrorMetadata() {
MetadataStore metadataStore = new MetadataStore();
// $NON-NLS-1$
Schema p1 = RealMetadataFactory.createPhysicalModel("p1", metadataStore);
// $NON-NLS-1$
Table t1 = RealMetadataFactory.createPhysicalGroup("t", p1);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
RealMetadataFactory.createElements(t1, new String[] { "a", "b" }, new String[] { "string", "string" });
// $NON-NLS-1$
Schema v1 = RealMetadataFactory.createVirtualModel("v1", metadataStore);
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode n1 = new QueryNode("SELECT convert(a, integer) as c, b FROM p1.t");
// $NON-NLS-1$
Table vt1 = RealMetadataFactory.createVirtualGroup("t1", v1, n1);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
RealMetadataFactory.createElements(vt1, new String[] { "c", "b" }, new String[] { "integer", "string" });
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode n3 = new QueryNode("SELECT c, b FROM v1.t1 UNION ALL SELECT c, b FROM v1.t1");
// $NON-NLS-1$
Table vu1 = RealMetadataFactory.createVirtualGroup("u1", v1, n3);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
RealMetadataFactory.createElements(vu1, new String[] { "c", "b" }, new String[] { "integer", "string" });
return RealMetadataFactory.createTransformationMetadata(metadataStore, "projectError");
}
Aggregations