use of org.teiid.language.NamedTable in project teiid by teiid.
the class MockConnector method createResultSetExecution.
@Override
public ResultSetExecution createResultSetExecution(QueryExpression query, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
Properties groupProps = new Properties();
// $NON-NLS-1$ //$NON-NLS-2$
groupProps.setProperty("customName", "CustomTableA");
NamedTable group = (NamedTable) query.getProjectedQuery().getFrom().get(0);
AbstractMetadataRecord groupMD = group.getMetadataObject();
TestCase.assertEquals(groupProps, groupMD.getProperties());
DerivedColumn symbl = query.getProjectedQuery().getDerivedColumns().get(0);
ColumnReference element = (ColumnReference) symbl.getExpression();
Column elementMD = element.getMetadataObject();
Properties elementProps = new Properties();
// $NON-NLS-1$ //$NON-NLS-2$
elementProps.setProperty("customPosition", "11");
TestCase.assertEquals(0, elementMD.getLength());
// $NON-NLS-1$
TestCase.assertEquals("Foo", elementMD.getDefaultValue());
// $NON-NLS-1$
TestCase.assertEquals("TrimNulls", elementMD.getFormat());
TestCase.assertEquals(String.class, elementMD.getJavaType());
TestCase.assertEquals(null, elementMD.getMaximumValue());
TestCase.assertEquals(null, elementMD.getMinimumValue());
// $NON-NLS-1$
TestCase.assertEquals("COLUMN1", elementMD.getNameInSource());
// $NON-NLS-1$
TestCase.assertEquals("STR", elementMD.getNativeType());
TestCase.assertEquals(NullType.Nullable, elementMD.getNullType());
TestCase.assertEquals(0, elementMD.getPosition());
TestCase.assertEquals(0, elementMD.getPrecision());
TestCase.assertEquals(0, elementMD.getScale());
TestCase.assertEquals(SearchType.Searchable, elementMD.getSearchType());
TestCase.assertEquals(false, elementMD.isAutoIncremented());
TestCase.assertEquals(true, elementMD.isCaseSensitive());
TestCase.assertEquals(elementProps, elementMD.getProperties());
DerivedColumn symbl2 = query.getProjectedQuery().getDerivedColumns().get(1);
ColumnReference element2 = (ColumnReference) symbl2.getExpression();
Column elementMD2 = element2.getMetadataObject();
Properties elementProps2 = new Properties();
// $NON-NLS-1$ //$NON-NLS-2$
elementProps2.setProperty("customPosition", "12");
TestCase.assertEquals(10, elementMD2.getLength());
// $NON-NLS-1$
TestCase.assertEquals("23", elementMD2.getDefaultValue());
// $NON-NLS-1$
TestCase.assertEquals("YesFormat", elementMD2.getFormat());
TestCase.assertEquals(Integer.class, elementMD2.getJavaType());
// $NON-NLS-1$
TestCase.assertEquals("1", elementMD2.getMaximumValue());
// $NON-NLS-1$
TestCase.assertEquals("100", elementMD2.getMinimumValue());
// $NON-NLS-1$
TestCase.assertEquals("COLUMN2", elementMD2.getNameInSource());
// $NON-NLS-1$
TestCase.assertEquals("INT", elementMD2.getNativeType());
TestCase.assertEquals(NullType.No_Nulls, elementMD2.getNullType());
TestCase.assertEquals(1, elementMD2.getPosition());
TestCase.assertEquals(0, elementMD2.getPrecision());
TestCase.assertEquals(10, elementMD2.getScale());
TestCase.assertEquals(SearchType.Searchable, elementMD2.getSearchType());
TestCase.assertEquals(true, elementMD2.isAutoIncremented());
TestCase.assertEquals(false, elementMD2.isCaseSensitive());
TestCase.assertEquals(elementProps2, elementMD2.getProperties());
ResultSetExecution exec = Mockito.mock(ResultSetExecution.class);
Mockito.stub(exec.next()).toReturn(null);
return exec;
}
use of org.teiid.language.NamedTable in project teiid by teiid.
the class SpreadsheetSQLVisitor method visit.
public void visit(Select obj) {
buffer.append(SELECT).append(Tokens.SPACE);
if (obj.getFrom() != null && !obj.getFrom().isEmpty()) {
NamedTable table = ((NamedTable) obj.getFrom().get(0));
this.worksheetTitle = table.getName();
if (table.getMetadataObject().getNameInSource() != null) {
this.worksheetTitle = table.getMetadataObject().getNameInSource();
}
}
append(obj.getDerivedColumns());
if (obj.getWhere() != null) {
buffer.append(Tokens.SPACE).append(WHERE).append(Tokens.SPACE);
append(obj.getWhere());
}
if (obj.getGroupBy() != null) {
buffer.append(Tokens.SPACE);
append(obj.getGroupBy());
}
if (obj.getOrderBy() != null) {
buffer.append(Tokens.SPACE);
append(obj.getOrderBy());
}
if (obj.getLimit() != null) {
if (obj.getLimit().getRowOffset() > 0) {
offsetValue = obj.getLimit().getRowOffset();
}
limitValue = obj.getLimit().getRowLimit();
}
}
use of org.teiid.language.NamedTable in project teiid by teiid.
the class JPQLSelectVisitor method handleJoin.
private JoinTable handleJoin(Join.JoinType joinType, NamedTable left, JoinTable right) throws TranslatorException {
// first we need to find correct parent for the left
JoinTable withParent = handleJoin(joinType, left, right.getParent(), false);
JoinTable withChild = handleJoin(joinType, left, right.getChild(), false);
NamedTable parent = (withParent.getParent() != null) ? withParent.getParent() : withChild.getParent();
if (parent != null) {
return handleJoin(joinType, left, parent, true);
}
throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14006));
}
use of org.teiid.language.NamedTable in project teiid by teiid.
the class JPQLSelectVisitor method handleJoin.
private JoinTable handleJoin(Join.JoinType joinType, TableReference left, TableReference right, boolean fixCorrelatedNames) {
// both sides are named tables
NamedTable leftTable = (NamedTable) left;
NamedTable rightTable = (NamedTable) right;
JoinTable joinTable = new JoinTable(leftTable, rightTable, joinType);
if (fixCorrelatedNames) {
// fix left table's correleated name
NamedTable table = this.implicitGroups.get(leftTable.getMetadataObject().getFullName());
if (table != null) {
table.setCorrelationName(leftTable.getCorrelationName());
}
// fix right table's correleated name
table = this.implicitGroups.get(rightTable.getMetadataObject().getFullName());
if (table != null) {
table.setCorrelationName(rightTable.getCorrelationName());
}
}
return joinTable;
}
use of org.teiid.language.NamedTable in project teiid by teiid.
the class CoherenceVisitor method visit.
public void visit(Select query) {
super.visit(query);
Iterator<DerivedColumn> selectSymbolItr = query.getDerivedColumns().iterator();
attributeNames = new String[query.getDerivedColumns().size()];
attributeTypes = new Class[query.getDerivedColumns().size()];
int i = 0;
while (selectSymbolItr.hasNext()) {
Column e = getElementFromSymbol(selectSymbolItr.next());
attributeNames[i] = this.getNameFromElement(e);
attributeTypes[i] = e.getJavaType();
i++;
}
List<TableReference> tables = query.getFrom();
TableReference t = tables.get(0);
if (t instanceof NamedTable) {
Table group = ((NamedTable) t).getMetadataObject();
tableName = group.getName();
}
}
Aggregations