Skip to content

Commit

Permalink
TEIID-2281 adding support for string import of nvarchar2 and varchar2.
Browse files Browse the repository at this point in the history
also refining the hive metadata load and reporting the accessnode
projection in the query plan
  • Loading branch information
shawkins committed Nov 2, 2012
1 parent a6eb3d6 commit 98456d8
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 53 deletions.
Expand Up @@ -28,8 +28,6 @@
import java.util.ArrayList;
import java.util.List;

import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.metadata.Column;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.Table;
Expand All @@ -47,18 +45,14 @@ public void getConnectorMetadata(Connection conn, MetadataFactory metadataFactor
}
}

private List<String> getTables(Connection conn) {
private List<String> getTables(Connection conn) throws SQLException {
ArrayList<String> tables = new ArrayList<String>();
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SHOW TABLES"); //$NON-NLS-1$
while (rs.next()){
tables.add(rs.getString(1));
}
rs.close();
} catch (SQLException e) {
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "HiveMetadataProcessor - failed getting table names"); //$NON-NLS-1$
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SHOW TABLES"); //$NON-NLS-1$
while (rs.next()){
tables.add(rs.getString(1));
}
rs.close();
return tables;
}

Expand Down Expand Up @@ -89,25 +83,23 @@ else if (type.equalsIgnoreCase("boolean")) { //$NON-NLS-1$
}
return TypeFacility.RUNTIME_NAMES.STRING;
}
private void addTable(String tableName, Connection conn, MetadataFactory metadataFactory) throws TranslatorException {
try {
Table table = metadataFactory.addTable(tableName);
table.setNameInSource(tableName);
table.setSupportsUpdate(true);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("DESCRIBE "+tableName); //$NON-NLS-1$
while (rs.next()){
String name = rs.getString(1);
String type = rs.getString(2);
String runtimeType = getRuntimeType(type);

Column column = metadataFactory.addColumn(name, runtimeType, table);
column.setNameInSource(name);
column.setUpdatable(true);
}
rs.close();
} catch (SQLException e) {
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "HiveMetadataProcessor - failed getting column names"); //$NON-NLS-1$

private void addTable(String tableName, Connection conn, MetadataFactory metadataFactory) throws SQLException {
Table table = addTable(metadataFactory, null, null, tableName, null, tableName);
if (table == null) {
return;
}
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("DESCRIBE "+tableName); //$NON-NLS-1$
while (rs.next()){
String name = rs.getString(1);
String type = rs.getString(2);
String runtimeType = getRuntimeType(type);

Column column = metadataFactory.addColumn(name, runtimeType, table);
column.setNameInSource(name);
column.setUpdatable(true);
}
rs.close();
}
}
Expand Up @@ -259,7 +259,7 @@ public void getMetadata(MetadataFactory metadataFactory, Connection conn) throws
throw new TranslatorException(JDBCPlugin.Event.TEIID11018, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11018));
}
JDBCMetdataProcessor metadataProcessor = createMetadataProcessor();
PropertiesUtils.setBeanProperties(metadataProcessor, metadataFactory.getImportProperties(), "importer"); //$NON-NLS-1$
PropertiesUtils.setBeanProperties(metadataProcessor, metadataFactory.getModelProperties(), "importer"); //$NON-NLS-1$
metadataProcessor.getConnectorMetadata(conn, metadataFactory);
} catch (SQLException e) {
throw new TranslatorException(JDBCPlugin.Event.TEIID11010, e);
Expand Down Expand Up @@ -732,7 +732,7 @@ public ResultSet executeStoredProcedure(CallableStatement statement, List<Argume
registerSpecificTypeOfOutParameter(statement, returnType, index++);
}

Iterator iter = preparedValues.iterator();
Iterator<?> iter = preparedValues.iterator();
while(iter.hasNext()){
Argument param = (Argument)iter.next();

Expand Down
Expand Up @@ -228,16 +228,13 @@ private Map<String, TableInfo> getTables(MetadataFactory metadataFactory,
String tableCatalog = tables.getString(1);
String tableSchema = tables.getString(2);
String tableName = tables.getString(3);
String remarks = tables.getString(5);
String fullName = getFullyQualifiedName(tableCatalog, tableSchema, tableName);
if (excludeTables != null && excludeTables.matcher(fullName).matches()) {
excludedTables++;
Table table = addTable(metadataFactory, tableCatalog, tableSchema,
tableName, remarks, fullName);
if (table == null) {
continue;
}
Table table = metadataFactory.addTable(useFullSchemaName?fullName:tableName);
table.setNameInSource(getFullyQualifiedName(tableCatalog, tableSchema, tableName, true));
table.setSupportsUpdate(true);
String remarks = tables.getString(5);
table.setAnnotation(remarks);
TableInfo ti = new TableInfo(tableCatalog, tableSchema, tableName, table);
tableMap.put(fullName, ti);
tableMap.put(tableName, ti);
Expand All @@ -248,6 +245,20 @@ private Map<String, TableInfo> getTables(MetadataFactory metadataFactory,
return tableMap;
}

protected Table addTable(MetadataFactory metadataFactory,
String tableCatalog, String tableSchema, String tableName,
String remarks, String fullName) {
if (excludeTables != null && excludeTables.matcher(fullName).matches()) {
excludedTables++;
return null;
}
Table table = metadataFactory.addTable(useFullSchemaName?fullName:tableName);
table.setNameInSource(getFullyQualifiedName(tableCatalog, tableSchema, tableName, true));
table.setSupportsUpdate(true);
table.setAnnotation(remarks);
return table;
}

private void getColumns(MetadataFactory metadataFactory,
DatabaseMetaData metadata, Map<String, TableInfo> tableMap)
throws SQLException {
Expand Down Expand Up @@ -327,7 +338,7 @@ private void processColumns(MetadataFactory metadataFactory,
columns.close();
}

private String getRuntimeType(int type, String typeName, int precision) {
protected String getRuntimeType(int type, String typeName, int precision) {
if (type == Types.BIT && precision > 1) {
type = Types.BINARY;
}
Expand Down
Expand Up @@ -126,7 +126,7 @@ public void append(LanguageObject obj) {
* @param object
* @param valuesbuffer
*/
private void translateSQLType(Class type, Object obj, StringBuilder valuesbuffer) {
protected void translateSQLType(Class<?> type, Object obj, StringBuilder valuesbuffer) {
if (obj == null) {
valuesbuffer.append(Reserved.NULL);
} else {
Expand Down
Expand Up @@ -56,10 +56,10 @@
import org.teiid.translator.jdbc.ExtractFunctionModifier;
import org.teiid.translator.jdbc.FunctionModifier;
import org.teiid.translator.jdbc.JDBCExecutionFactory;
import org.teiid.translator.jdbc.JDBCMetdataProcessor;
import org.teiid.translator.jdbc.JDBCPlugin;
import org.teiid.translator.jdbc.LocateFunctionModifier;
import org.teiid.translator.jdbc.SQLConversionVisitor;
import org.teiid.translator.jdbc.TranslatedCommand;


@Translator(name="oracle", description="A translator for Oracle 9i Database or later")
Expand Down Expand Up @@ -757,4 +757,19 @@ public boolean supportsArrayType() {
return true;
}

@Override
protected JDBCMetdataProcessor createMetadataProcessor() {
return new JDBCMetdataProcessor() {
@Override
protected String getRuntimeType(int type, String typeName,
int precision) {
//overrides for varchar2 and nvarchar2
if (type == 1111 || type == 12) {
return TypeFacility.RUNTIME_NAMES.STRING;
}
return super.getRuntimeType(type, typeName, precision);
}
};
}

}
Expand Up @@ -35,9 +35,9 @@
import org.teiid.client.plan.PlanNode;
import org.teiid.common.buffer.BlockedException;
import org.teiid.common.buffer.BufferManager;
import org.teiid.common.buffer.BufferManager.BufferReserveMode;
import org.teiid.common.buffer.TupleBatch;
import org.teiid.common.buffer.TupleSource;
import org.teiid.common.buffer.BufferManager.BufferReserveMode;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.query.QueryPlugin;
Expand All @@ -64,7 +64,8 @@

public class AccessNode extends SubqueryAwareRelationalNode {

private static final int MAX_CONCURRENT = 10; //TODO: this could be settable via a property
private static final Object[] NO_PROJECTION = new Object[0];
private static final int MAX_CONCURRENT = 10; //TODO: this could be settable via a property
// Initialization state
private Command command;
private String modelName;
Expand Down Expand Up @@ -212,7 +213,7 @@ public void minimizeProject(Command atomicCommand) {
i++;
}
if (!shouldProject) {
this.projection = new Object[0];
this.projection = NO_PROJECTION;
} else if (query.getOrderBy() != null) {
for (OrderByItem item : query.getOrderBy().getOrderByItems()) {
Integer index = uniqueSymbols.get(SymbolMap.getExpression(item.getSymbol()));
Expand Down Expand Up @@ -434,6 +435,10 @@ public PlanNode getDescriptionProperties() {
PlanNode props = super.getDescriptionProperties();
props.addProperty(PROP_SQL, this.command.toString());
props.addProperty(PROP_MODEL_NAME, this.modelName);
if (this.projection != null && this.projection.length > 0 && this.originalSelect != null) {
props.addProperty(PROP_SELECT_COLS, this.originalSelect.toString());
}
props.addProperty(PROP_MODEL_NAME, this.modelName);
if (this.info != null) {
props.addProperty(PROP_SHARING_ID, String.valueOf(this.info.id));
}
Expand All @@ -451,13 +456,6 @@ public void setConnectorBindingId(String connectorBindingId) {
@Override
protected Collection<? extends LanguageObject> getObjects() {
ArrayList<LanguageObject> list = new ArrayList<LanguageObject>();
if (projection != null) {
for (Object obj : projection) {
if (obj instanceof LanguageObject) {
list.add((LanguageObject)obj);
}
}
}
if (shouldEvaluate) {
//collect any evaluatable subqueries
for (SubqueryContainer<?> container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(this.command)) {
Expand Down

0 comments on commit 98456d8

Please sign in to comment.