Skip to content

Commit

Permalink
TEIID-3044 adding implementations for getFunctions and
Browse files Browse the repository at this point in the history
getFunctionColumns
  • Loading branch information
shawkins committed Aug 19, 2014
1 parent 8262f8a commit 4dcf2de
Show file tree
Hide file tree
Showing 15 changed files with 282 additions and 34 deletions.
1 change: 1 addition & 0 deletions build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
Expand Up @@ -29,6 +29,7 @@ <H2><A NAME="Highlights"></A>Highlights</H2>
<li>TEIID-3009 <b>WITH project minimization</b> - common table expressions will have their project columns minimized.
<li>TEIID-3038 <b>geoSpatial support for MongoDB</b> translator
<li>TEIID-3050 <b>Increased Insert Performance</b> with sources that support batching or insert with iterator.
<li>TEIID-3044 <b>Function Metadata</b> is available through system tables and DatabaseMetaData.
</ul>

<h2><a name="Compatibility">Compatibility Issues</a></h2>
Expand Down
136 changes: 134 additions & 2 deletions client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java
Expand Up @@ -255,6 +255,29 @@ final private static class RUNTIME_MODEL{
.append(" WHERE UCASE(VDBName)").append(LIKE_ESCAPE)//$NON-NLS-1$
.append(" AND UCASE(Name)").append(LIKE_ESCAPE)//$NON-NLS-1$
.append(" ORDER BY TABLE_SCHEM").toString(); //$NON-NLS-1$

private static final String QUERY_FUNCTIONS = new StringBuffer("SELECT VDBName AS Function_CAT, SchemaName AS FUNCTION_SCHEM, " //$NON-NLS-1$
+ "Name AS FUNCTION_NAME, Description as REMARKS, 1 as FUNCTION_TYPE, UID AS SPECIFIC_NAME") //$NON-NLS-1$
.append(" FROM ").append(RUNTIME_MODEL.VIRTUAL_MODEL_NAME).append(".Functions") //$NON-NLS-1$ //$NON-NLS-2$
.append(" WHERE UCASE(VDBName)").append(LIKE_ESCAPE)//$NON-NLS-1$
.append(" AND UCASE(SchemaName)").append(LIKE_ESCAPE)//$NON-NLS-1$
.append(" AND UCASE(Name)").append(LIKE_ESCAPE)//$NON-NLS-1$
.append(" ORDER BY FUNCTION_CAT, FUNCTION_SCHEM, FUNCTION_NAME, SPECIFIC_NAME").toString(); //$NON-NLS-1$

private static final String QUERY_FUNCTION_COLUMNS = new StringBuffer("SELECT VDBName AS Function_CAT, SchemaName AS FUNCTION_SCHEM, ") //$NON-NLS-1$
.append("FunctionName AS FUNCTION_NAME, Name as COLUMN_NAME, CASE WHEN Type = 'ReturnValue' Then 4 WHEN Type = 'In' Then 1 ELSE 0 END AS COLUMN_TYPE") //$NON-NLS-1$
.append(", 1 AS DATA_TYPE") //$NON-NLS-1$
.append(", DataType AS TYPE_NAME, \"Precision\" AS \"PRECISION\", TypeLength AS LENGTH, convert(Scale, short) AS SCALE") //$NON-NLS-1$
.append(", Radix AS RADIX, convert(decodeString(NullType, '") //$NON-NLS-1$
.append(PROC_COLUMN_NULLABILITY_MAPPING).append("', ','), integer) AS NULLABLE") //$NON-NLS-1$
.append(", Description AS REMARKS, NULL AS CHAR_OCTET_LENGTH, Position AS ORDINAL_POSITION,") //$NON-NLS-1$
.append(IS_NULLABLE).append(", FunctionUID as SPECIFIC_NAME") //$NON-NLS-1$
.append(" FROM ").append(RUNTIME_MODEL.VIRTUAL_MODEL_NAME).append(".FunctionParams") //$NON-NLS-1$ //$NON-NLS-2$
.append(" WHERE UCASE(VDBName)").append(LIKE_ESCAPE)//$NON-NLS-1$
.append(" AND UCASE(SchemaName)").append(LIKE_ESCAPE)//$NON-NLS-1$
.append(" AND UCASE(FunctionName)").append(LIKE_ESCAPE)//$NON-NLS-1$
.append(" AND UCASE(Name)").append(LIKE_ESCAPE)//$NON-NLS-1$
.append(" ORDER BY FUNCTION_CAT, FUNCTION_SCHEM, FUNCTION_NAME, SPECIFIC_NAME, ORDINAL_POSITION").toString(); //$NON-NLS-1$

private final String TABLE_TYPE;

Expand Down Expand Up @@ -2267,12 +2290,121 @@ public ResultSet getClientInfoProperties() throws SQLException {
public ResultSet getFunctionColumns(String catalog, String schemaPattern,
String functionNamePattern, String columnNamePattern)
throws SQLException {
throw SqlUtil.createFeatureNotSupportedException();
if (catalog == null) {
catalog = PERCENT;
}

if (schemaPattern == null) {
schemaPattern = PERCENT;
}

if (functionNamePattern == null) {
functionNamePattern = PERCENT;
}

if (columnNamePattern == null) {
columnNamePattern = PERCENT;
}

List records = new ArrayList ();

ResultSetMetaData rmetadata = null;
ResultSetImpl results = null;
PreparedStatementImpl prepareQuery = null;
try {
prepareQuery = driverConnection.prepareStatement(QUERY_FUNCTION_COLUMNS);
prepareQuery.setString(1, catalog.toUpperCase());
prepareQuery.setString(2, schemaPattern.toUpperCase());
prepareQuery.setString(3, functionNamePattern.toUpperCase());
prepareQuery.setString(4, columnNamePattern.toUpperCase());
results = prepareQuery.executeQuery();
// Get the metadata for the results
rmetadata = results.getMetaData();
int cols = rmetadata.getColumnCount();
while (results.next ()) {
List currentRow = new ArrayList (cols);
for(int i=0; i < cols; i++) {
currentRow.add(results.getObject(i+1));
}
String typeName = (String)currentRow.get(6);
Integer length = (Integer)currentRow.get(8);
Integer precision = (Integer)currentRow.get(7);
if (precision != null && precision <= 0) {
currentRow.set(7, JDBCSQLTypeInfo.getDefaultPrecision(typeName));
}
if (length != null && length <= 0) {
currentRow.set(8, JDBCSQLTypeInfo.getDefaultPrecision(typeName));
}
if (typeName != null) {
currentRow.set(5, JDBCSQLTypeInfo.getSQLType(typeName));
} else {
currentRow.set(5, null);
}
// add the current row to the list of records.
records.add(currentRow);
}// end of while

logger.fine(JDBCPlugin.Util.getString("MMDatabaseMetadata.getfunctioncolumns_success")); //$NON-NLS-1$

// construct results object from column values and their metadata
return dummyStatement().createResultSet(records, rmetadata);
} catch(Exception e) {
throw TeiidSQLException.create(e, JDBCPlugin.Util.getString("MMDatabaseMetadata.getfunctioncolumns_error", e.getMessage())); //$NON-NLS-1$
} finally {
if (prepareQuery != null) {
prepareQuery.close();
}
}
}

public ResultSet getFunctions(String catalog, String schemaPattern,
String functionNamePattern) throws SQLException {
throw SqlUtil.createFeatureNotSupportedException();
if (catalog == null) {
catalog = PERCENT;
}

if (schemaPattern == null) {
schemaPattern = PERCENT;
}

if (functionNamePattern == null) {
functionNamePattern = PERCENT;
}
List records = new ArrayList ();

ResultSetMetaData rmetadata = null;
ResultSetImpl results = null;
PreparedStatementImpl prepareQuery = null;
try {
prepareQuery = driverConnection.prepareStatement(QUERY_FUNCTIONS);
prepareQuery.setString(1, catalog.toUpperCase());
prepareQuery.setString(2, schemaPattern.toUpperCase());
prepareQuery.setString(3, functionNamePattern.toUpperCase());
results = prepareQuery.executeQuery();
// Get the metadata for the results
rmetadata = results.getMetaData();
int cols = rmetadata.getColumnCount();
while (results.next ()) {
List currentRow = new ArrayList(cols);

for(int i = 0; i < cols; i++) {
currentRow.add(results.getObject(i+1));
}

records.add(currentRow);
}

logger.fine(JDBCPlugin.Util.getString("MMDatabaseMetadata.getfunctions_success")); //$NON-NLS-1$

// construct results object from column values and their metadata
return dummyStatement().createResultSet(records, rmetadata);
} catch(Exception e) {
throw TeiidSQLException.create(e, JDBCPlugin.Util.getString("MMDatabaseMetadata.getfunctions_error", e.getMessage())); //$NON-NLS-1$
} finally {
if (prepareQuery != null) {
prepareQuery.close();
}
}
}

public RowIdLifetime getRowIdLifetime() throws SQLException {
Expand Down
Expand Up @@ -257,7 +257,7 @@ public int[] executeBatch() throws SQLException {
}

@Override
public ResultSet executeQuery() throws SQLException {
public ResultSetImpl executeQuery() throws SQLException {
executeSql(new String[] {this.prepareSql}, false, ResultsMode.RESULTSET, true, null, autoGeneratedKeys);
return resultSet;
}
Expand Down
6 changes: 5 additions & 1 deletion client/src/main/resources/org/teiid/jdbc/i18n.properties
Expand Up @@ -66,7 +66,11 @@ MMDatabaseMetadata.getProcCol_success=Successfully obtained metadata info for th
MMDatabaseMetadata.getProc_error=Error trying to get metadata information for procedure name like {0} - {1}.
MMDatabaseMetadata.getProc_success=Successfully obtained metadata information for the procedure whose name matches {0}.
MMDatabaseMetadata.getschema_error=Error trying to obtain schema metadata info on this connection: {0}.
MMDatabaseMetadata.getschema_success=Schema metadata info successfully obtained for this connection.
MMDatabaseMetadata.getschema_success=Schema metadata info successfully obtained for this connection.
MMDatabaseMetadata.getfunctions_error=Error trying to obtain function metadata info on this connection: {0}.
MMDatabaseMetadata.getfunctions_success=Function metadata info successfully obtained for this connection.
MMDatabaseMetadata.getfunctioncolumns_error=Error trying to obtain function param metadata info on this connection: {0}.
MMDatabaseMetadata.getfunctioncolumns_success=Function param metadata info successfully obtained for this connection.
MMDatabaseMetadata.getTable_error=Error trying to obtain metadata information for the tables that match {0}: {1}.
MMDatabaseMetadata.getTable_success=Successfully obtained metadata information for the table names that match {0}.
MMDatabaseMetadata.getTableType_success=Successfully obtained metadata information for the table types.
Expand Down
Expand Up @@ -523,9 +523,9 @@ public void fillRow(List<Object> row, FunctionParameter param,
row.add(parent.getName());
row.add(parent.getUUID());
row.add(param.getName());
row.add(param.getPosition()==0?"ReturnValue":"In"); //$NON-NLS-1$ //$NON-NLS-2$
row.add(param.getPosition());
row.add(param.getRuntimeType());
row.add(param.getPosition());
row.add(param.getPosition()==0?"ReturnValue":"In"); //$NON-NLS-1$ //$NON-NLS-2$
row.add(param.getPrecision());
row.add(param.getLength());
row.add(param.getScale());
Expand Down
4 changes: 2 additions & 2 deletions engine/src/main/resources/org/teiid/metadata/SYS.sql
Expand Up @@ -143,7 +143,7 @@ CREATE FOREIGN TABLE FunctionParams (
Radix integer NOT NULL,
NullType string(10) NOT NULL,
/*UID string(50),*/
Description string(255),
Description string(4000),
/*UNIQUE (UID),*/
PRIMARY KEY (VDBName, SchemaName, FunctionName, Name),
FOREIGN KEY (VDBName, SchemaName, FunctionName) REFERENCES Functions (VDBName, SchemaName, Name)
Expand All @@ -155,7 +155,7 @@ CREATE FOREIGN TABLE Functions (
Name string(255) NOT NULL,
NameInSource string(255),
UID string(50) NOT NULL,
Description string(255),
Description string(4000),
IsVarArgs boolean,
PRIMARY KEY (VDBName, SchemaName, Name),
FOREIGN KEY (VDBName, SchemaName) REFERENCES Schemas (VDBName, Name),
Expand Down
Expand Up @@ -58,7 +58,7 @@
@SuppressWarnings("nls")
public class TestMMDatabaseMetaData {

private static final boolean REPLACE_EXPECTED = false;
private static final boolean REPLACE_EXPECTED = true;
private static final boolean WRITE_ACTUAL_RESULTS_TO_FILE = false;
private static final boolean PRINT_RESULTSETS_TO_CONSOLE = false;

Expand Down Expand Up @@ -752,6 +752,20 @@ public void testGetProceduresWithEscape() throws Exception {
ResultSet rs2 = dbmd.getProcedures("foo", "Foo%", null); //$NON-NLS-1$ //$NON-NLS-2$
compareResultSet(rs, rs1, rs2);
}

@Test
public void testGetFunctions() throws Exception {
ResultSet rs = dbmd.getFunctions(null, null, null); //$NON-NLS-1$
ResultSet rs1 = dbmd.getFunctions(null, "pg%", "%pg%"); //$NON-NLS-1$
compareResultSet(rs, rs1);
}

@Test
public void testGetFunctionColumns() throws Exception {
ResultSet rs = dbmd.getFunctionColumns(null, null, null, null); //$NON-NLS-1$
ResultSet rs1 = dbmd.getFunctionColumns(null, "pg%", "%pg%", null); //$NON-NLS-1$
compareResultSet(rs, rs1);
}
///////////////////////////Helper Method//////////////////////////////

private void helpTestSupportsConverts(int from, int to, boolean result) throws Exception {
Expand Down

0 comments on commit 4dcf2de

Please sign in to comment.