Author: shawkins
Date: 2011-04-15 16:44:09 -0400 (Fri, 15 Apr 2011)
New Revision: 3095
Added:
trunk/api/src/main/java/org/teiid/events/EventDistributorFactory.java
trunk/api/src/main/java/org/teiid/metadata/ColumnStats.java
trunk/api/src/main/java/org/teiid/metadata/TableStats.java
trunk/api/src/main/java/org/teiid/metadata/ViewDefinition.java
Modified:
trunk/api/src/main/java/org/teiid/events/EventDistributor.java
trunk/api/src/main/java/org/teiid/metadata/MetadataProvider.java
trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
trunk/engine/src/main/java/org/teiid/query/mapping/relational/QueryNode.java
trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java
Log:
TEIID-1507 further refining cache invalidation, adding the initial runtime costing logic,
and removing the concept of user specific views.
Modified: trunk/api/src/main/java/org/teiid/events/EventDistributor.java
===================================================================
--- trunk/api/src/main/java/org/teiid/events/EventDistributor.java 2011-04-15 18:12:29 UTC
(rev 3094)
+++ trunk/api/src/main/java/org/teiid/events/EventDistributor.java 2011-04-15 20:44:09 UTC
(rev 3095)
@@ -24,41 +24,48 @@
import java.util.List;
+import org.teiid.metadata.ColumnStats;
+import org.teiid.metadata.TableStats;
+
/**
* Distributes events across the Teiid cluster
*/
public interface EventDistributor {
/**
- * Update the given materialized view row using the internal mat view name
#MAT_VIEWFQN.
+ * Update the given materialized view row.
* The tuple is expected to be in table order, which has the primary key first.
* Deletes need to only send the key, not the entire row contents.
*
* @param vdbName
* @param vdbVersion
- * @param matViewFqn
+ * @param schema
+ * @param viewName
* @param tuple
* @param delete
*/
- void updateMatViewRow(String vdbName, int vdbVersion, String matViewFqn, List<?>
tuple, boolean delete);
+ void updateMatViewRow(String vdbName, int vdbVersion, String schema, String viewName,
List<?> tuple, boolean delete);
/**
- * Notify that the metadata has been changed for the given fqns.
- * A fqn has the form schema.entityname.
- * This typically implies that the costing metadata has changed, but may also indicate
- * a view definition has changed.
+ * Notify that the metadata has been changed for the given table or view.
* @param vdbName
* @param vdbVersion
- * @param fqns
+ * @param schema
+ * @param objectNames
*/
- void schemaModification(String vdbName, int vdbVersion, String... fqns);
+ void schemaModification(String vdbName, int vdbVersion, String schema, String...
objectNames);
/**
* Notify that the table data has changed.
- * A table fqn has the form schema.tablename.
* @param vdbName
* @param vdbVersion
- * @param tableFqns
+ * @param schema
+ * @param tableNames
*/
- void dataModification(String vdbName, int vdbVersion, String... tableFqns);
+ void dataModification(String vdbName, int vdbVersion, String schema, String...
tableNames);
+
+ void setTableStats(String vdbName, int vdbVersion, String schemaName, String tableName,
TableStats stats);
+
+ void setColumnStats(String vdbName, int vdbVersion, String schemaName, String tableName,
String columnName, ColumnStats stats);
+
}
Added: trunk/api/src/main/java/org/teiid/events/EventDistributorFactory.java
===================================================================
--- trunk/api/src/main/java/org/teiid/events/EventDistributorFactory.java
(rev 0)
+++ trunk/api/src/main/java/org/teiid/events/EventDistributorFactory.java 2011-04-15
20:44:09 UTC (rev 3095)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.events;
+
+public interface EventDistributorFactory {
+
+ /**
+ * Get an {@link EventDistributor} that will distribute events to
+ * all members.
+ * @return
+ */
+ EventDistributor getEventDistributor();
+
+}
Property changes on:
trunk/api/src/main/java/org/teiid/events/EventDistributorFactory.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/api/src/main/java/org/teiid/metadata/ColumnStats.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/ColumnStats.java
(rev 0)
+++ trunk/api/src/main/java/org/teiid/metadata/ColumnStats.java 2011-04-15 20:44:09 UTC
(rev 3095)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.metadata;
+
+public class ColumnStats {
+
+ private int numDistinctValues = -1;
+ private int numNullValues = -1;
+ private String min;
+ private String max;
+
+ public int getNumDistinctValues() {
+ return numDistinctValues;
+ }
+
+ public void setNumDistinctValues(int numDistinctValues) {
+ this.numDistinctValues = numDistinctValues;
+ }
+
+ public int getNumNullValues() {
+ return numNullValues;
+ }
+
+ public void setNumNullValues(int numNullValues) {
+ this.numNullValues = numNullValues;
+ }
+
+ public String getMin() {
+ return min;
+ }
+
+ public void setMin(String min) {
+ this.min = min;
+ }
+
+ public String getMax() {
+ return max;
+ }
+
+ public void setMax(String max) {
+ this.max = max;
+ }
+
+}
Property changes on: trunk/api/src/main/java/org/teiid/metadata/ColumnStats.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/api/src/main/java/org/teiid/metadata/MetadataProvider.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/MetadataProvider.java 2011-04-15 18:12:29
UTC (rev 3094)
+++ trunk/api/src/main/java/org/teiid/metadata/MetadataProvider.java 2011-04-15 20:44:09
UTC (rev 3095)
@@ -29,35 +29,6 @@
*/
public interface MetadataProvider {
- public enum Scope {
- /**
- * The {@link ViewDefinition} applies only to the calling user
- */
- USER,
- /**
- * The {@link ViewDefinition} applies to all users
- */
- VDB
- }
-
- public static class ViewDefinition {
- private String sql;
- private Scope scope = Scope.VDB;
-
- public ViewDefinition(String sql, Scope scope) {
- this.sql = sql;
- this.scope = scope;
- }
-
- public String getSql() {
- return sql;
- }
-
- public Scope getScope() {
- return scope;
- }
- }
-
/**
* Returns an updated {@link ViewDefinition} or null if the default view definition
* should be used.
Added: trunk/api/src/main/java/org/teiid/metadata/TableStats.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/TableStats.java
(rev 0)
+++ trunk/api/src/main/java/org/teiid/metadata/TableStats.java 2011-04-15 20:44:09 UTC
(rev 3095)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.metadata;
+
+public class TableStats {
+
+ private int cardinality;
+
+ public int getCardinality() {
+ return cardinality;
+ }
+
+ public void setCardinality(int cardinality) {
+ this.cardinality = cardinality;
+ }
+
+}
Property changes on: trunk/api/src/main/java/org/teiid/metadata/TableStats.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/api/src/main/java/org/teiid/metadata/ViewDefinition.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/ViewDefinition.java
(rev 0)
+++ trunk/api/src/main/java/org/teiid/metadata/ViewDefinition.java 2011-04-15 20:44:09 UTC
(rev 3095)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.metadata;
+
+public class ViewDefinition {
+ private String sql;
+
+ public ViewDefinition(String sql) {
+ this.sql = sql;
+ }
+
+ public String getSql() {
+ return sql;
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/api/src/main/java/org/teiid/metadata/ViewDefinition.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
===================================================================
--- trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2011-04-15 18:12:29
UTC (rev 3094)
+++ trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2011-04-15 20:44:09
UTC (rev 3095)
@@ -42,9 +42,13 @@
import org.teiid.language.SetQuery;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
+import org.teiid.metadata.Column;
+import org.teiid.metadata.ColumnStats;
import org.teiid.metadata.FunctionMethod;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.metadata.Table;
+import org.teiid.metadata.TableStats;
@@ -805,6 +809,14 @@
}
+ public boolean updateTableStats(Table table, TableStats stats, C conn) throws
TranslatorException {
+ return false;
+ }
+
+ public boolean updateColumnStats(Column column, ColumnStats stats, C conn) throws
TranslatorException {
+ return false;
+ }
+
/**
* Indicates if LOBs are usable after the execution is closed.
* @return true if LOBs can be used after close
Modified: trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java 2011-04-15
18:12:29 UTC (rev 3094)
+++ trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java 2011-04-15
20:44:09 UTC (rev 3095)
@@ -197,9 +197,9 @@
* @param splitter Characters to split on
* @return List of String pieces from full string
*/
- public static List split(String str, String splitter) {
+ public static List<String> split(String str, String splitter) {
StringTokenizer tokens = new StringTokenizer(str, splitter);
- ArrayList l = new ArrayList(tokens.countTokens());
+ ArrayList<String> l = new ArrayList<String>(tokens.countTokens());
while(tokens.hasMoreTokens()) {
l.add(tokens.nextToken());
}
@@ -213,8 +213,8 @@
* @param delimiter The sub-string which is used to break the target.
* @return List of String from the target.
*/
- public static List splitOnEntireString(String target, String delimiter) {
- ArrayList result = new ArrayList();
+ public static List<String> splitOnEntireString(String target, String delimiter)
{
+ ArrayList<String> result = new ArrayList<String>();
if (delimiter.length() > 0) {
int index = 0;
int indexOfNextMatch = target.indexOf(delimiter);
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2011-04-15
18:12:29 UTC (rev 3094)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2011-04-15
20:44:09 UTC (rev 3095)
@@ -37,6 +37,7 @@
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
@@ -60,8 +61,12 @@
import org.teiid.language.SetQuery.Operation;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
+import org.teiid.metadata.Column;
+import org.teiid.metadata.ColumnStats;
import org.teiid.metadata.MetadataFactory;
import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.metadata.Table;
+import org.teiid.metadata.TableStats;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.ExecutionFactory;
import org.teiid.translator.ProcedureExecution;
@@ -1084,5 +1089,67 @@
*/
public boolean useSelectLimit() {
return false;
- }
+ }
+
+ public static List<String> parseName(String tableName, char escape, char delim) {
+ boolean quoted = false;
+ boolean escaped = false;
+ List<String> nameParts = new LinkedList<String>();
+ StringBuilder current = new StringBuilder();
+ for (int i = 0; i < tableName.length(); i++) {
+ char c = tableName.charAt(i);
+ if (quoted) {
+ if (c == escape) {
+ if (escaped) {
+ current.append(c);
+ }
+ escaped = !escaped;
+ } else if (c == delim) {
+ if (escaped) {
+ escaped = false;
+ quoted = false;
+ nameParts.add(current.toString());
+ current = new StringBuilder();
+ } else {
+ current.append(c);
+ }
+ } else {
+ current.append(c);
+ }
+ } else {
+ if (c == escape) {
+ if (current.length() == 0) {
+ quoted = true;
+ } else {
+ current.append(c);
+ }
+ } else if (c == delim) {
+ quoted = false;
+ nameParts.add(current.toString());
+ current = new StringBuilder();
+ } else {
+ current.append(c);
+ }
+ }
+ }
+ if (current.length() > 0) {
+ nameParts.add(current.toString());
+ }
+ return nameParts;
+ }
+
+ @Override
+ public boolean updateColumnStats(Column column, ColumnStats stats,
+ Connection conn) throws TranslatorException {
+ // TODO Auto-generated method stub
+ return super.updateColumnStats(column, stats, conn);
+ }
+
+
+ @Override
+ public boolean updateTableStats(Table table, TableStats stats,
+ Connection conn) throws TranslatorException {
+ return super.updateTableStats(table, stats, conn);
+ }
+
}
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java 2011-04-15
18:12:29 UTC (rev 3094)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java 2011-04-15
20:44:09 UTC (rev 3095)
@@ -84,7 +84,6 @@
private boolean widenUnsingedTypes = true;
private boolean quoteNameInSource = true;
private boolean useProcedureSpecificName;
- //TODO add an option to not fully qualify name in source
private Set<String> unsignedTypes = new HashSet<String>();
private String quoteString;
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java 2011-04-15
18:12:29 UTC (rev 3094)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java 2011-04-15
20:44:09 UTC (rev 3095)
@@ -24,14 +24,20 @@
*/
package org.teiid.translator.jdbc.oracle;
+import java.sql.CallableStatement;
+import java.sql.Connection;
import java.sql.PreparedStatement;
+import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
import org.teiid.language.ColumnReference;
import org.teiid.language.Command;
@@ -49,7 +55,10 @@
import org.teiid.language.SetQuery.Operation;
import org.teiid.language.visitor.CollectorVisitor;
import org.teiid.metadata.Column;
+import org.teiid.metadata.ColumnStats;
import org.teiid.metadata.FunctionMethod;
+import org.teiid.metadata.Table;
+import org.teiid.metadata.TableStats;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.SourceSystemFunctions;
import org.teiid.translator.Translator;
@@ -77,6 +86,35 @@
public final static String ROWNUM = "ROWNUM"; //$NON-NLS-1$
public final static String SEQUENCE = ":SEQUENCE="; //$NON-NLS-1$
+ private static final String NUMBER = "number"; //$NON-NLS-1$
+ private static final char escape = '"';
+ private static final char delim = '.';
+
+ private final static Map<Class<?>, String> type_to_raw_mapping = new
HashMap<Class<?>, String>();
+ private final static Map<Class<?>, Integer> type_to_jdbc_mapping = new
HashMap<Class<?>, Integer>();
+ private final static Map<String, String> native_to_raw_mapping = new
TreeMap<String, String>();
+
+ static {
+ type_to_raw_mapping.put(TypeFacility.RUNTIME_TYPES.BOOLEAN, NUMBER);
+ type_to_raw_mapping.put(TypeFacility.RUNTIME_TYPES.BYTE, NUMBER);
+ type_to_raw_mapping.put(TypeFacility.RUNTIME_TYPES.SHORT, NUMBER);
+ type_to_raw_mapping.put(TypeFacility.RUNTIME_TYPES.INTEGER, NUMBER);
+ type_to_raw_mapping.put(TypeFacility.RUNTIME_TYPES.LONG, NUMBER);
+ type_to_raw_mapping.put(TypeFacility.RUNTIME_TYPES.FLOAT, NUMBER);
+ type_to_raw_mapping.put(TypeFacility.RUNTIME_TYPES.DOUBLE, NUMBER);
+ type_to_raw_mapping.put(TypeFacility.RUNTIME_TYPES.STRING, "varchar2");
//$NON-NLS-1$
+
+ native_to_raw_mapping.put("varchar2", "varchar2");
//$NON-NLS-1$ //$NON-NLS-2$
+ native_to_raw_mapping.put("nvarchar2", "nvarchar2");
//$NON-NLS-1$ //$NON-NLS-2$
+ native_to_raw_mapping.put("binary_float", "binary_float");
//$NON-NLS-1$ //$NON-NLS-2$
+ native_to_raw_mapping.put("binary_integer",
"binary_integer"); //$NON-NLS-1$ //$NON-NLS-2$
+ native_to_raw_mapping.put("binary_double", "binary_double");
//$NON-NLS-1$ //$NON-NLS-2$
+
+ type_to_jdbc_mapping.put(TypeFacility.RUNTIME_TYPES.DATE, Types.DATE);
+ type_to_jdbc_mapping.put(TypeFacility.RUNTIME_TYPES.TIME, Types.DATE);
+ type_to_jdbc_mapping.put(TypeFacility.RUNTIME_TYPES.TIMESTAMP, Types.DATE);
+ }
+
public void start() throws TranslatorException {
super.start();
@@ -508,4 +546,157 @@
public boolean supportsAggregatesEnhancedNumeric() {
return true;
}
+
+ @Override
+ public boolean updateTableStats(Table table, TableStats stats, Connection conn)
+ throws TranslatorException {
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ String qualifiedTableName = table.getNameInSource();
+ if (qualifiedTableName == null) {
+ return false;
+ }
+ if (DUAL.equalsIgnoreCase(qualifiedTableName)) {
+ stats.setCardinality(1);
+ return false;
+ }
+ List<String> nameParts = JDBCExecutionFactory.parseName(qualifiedTableName,
escape, delim);
+ if (nameParts.size() < 2) {
+ return false;
+ }
+ String schemaName = nameParts.get(nameParts.size() - 2);
+ String tableName = nameParts.get(nameParts.size() - 1);
+ try {
+ try {
+ stmt = conn.prepareStatement("select num_rows from ALL_TABLES where
owner = ? AND table_name = ?"); //$NON-NLS-1$
+ stmt.setString(1, schemaName);
+ stmt.setString(2, tableName);
+ rs = stmt.executeQuery();
+ if(rs.next()) {
+ stats.setCardinality(rs.getInt(1));
+ return true;
+ }
+ } finally {
+ if(rs != null) {
+ rs.close();
+ }
+ if(stmt != null) {
+ stmt.close();
+ }
+ }
+ } catch (SQLException e) {
+ throw new TranslatorException(e);
+ }
+ return false;
+ }
+
+ @Override
+ public boolean updateColumnStats(Column column, ColumnStats stats,
+ Connection conn) throws TranslatorException {
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ String columnName = column.getNameInSource();
+ if (columnName == null) {
+ columnName = column.getName();
+ }
+ String qualifiedTableName = column.getParent().getNameInSource();
+ if (qualifiedTableName == null) {
+ return false;
+ }
+ if (DUAL.equalsIgnoreCase(qualifiedTableName)) {
+ return false;
+ }
+ List<String> nameParts = JDBCExecutionFactory.parseName(qualifiedTableName,
escape, delim);
+ if (nameParts.size() < 2) {
+ return false;
+ }
+ String schemaName = nameParts.get(nameParts.size() - 2);
+ String tableName = nameParts.get(nameParts.size() - 1);
+ try {
+ try {
+ String sql = "select num_distinct, num_nulls"; //$NON-NLS-1$
+ boolean knownType = true;
+ String type = null;
+ Integer jdbcType = null;
+ if (column.getNativeType() != null) {
+ type = native_to_raw_mapping.get(column.getNativeType());
+ }
+ Class<?> clazzType =
TypeFacility.getDataTypeClass(column.getRuntimeType());
+ if (type == null) {
+ type = type_to_raw_mapping.get(clazzType);
+ }
+ if (type != null) {
+ //TODO: could split into two queries to ensure that we at least get the
ndv/nnv
+ sql += ", utl_raw.cast_to_"+type+"(low_value),
utl_raw.cast_to_"+type+"(high_value)"; //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
+ } else {
+ //TODO could get type from the databasemetadata or store the type in the
extension metadata
+ sql += ", low_value, high_value"; //$NON-NLS-1$
+ knownType = false;
+ jdbcType = type_to_jdbc_mapping.get(clazzType);
+ }
+
+ sql += " from ALL_TAB_COL_STATISTICS where owner=? and TABLE_NAME = ?
and COLUMN_NAME = ?"; //$NON-NLS-1$
+ stmt = conn.prepareStatement(sql);
+ stmt.setString(1, schemaName);
+ stmt.setString(2, tableName);
+ stmt.setString(3, columnName);
+ rs = stmt.executeQuery();
+ if(rs.next()) {
+ stats.setNumDistinctValues(rs.getInt(1));
+ stats.setNumNullValues(rs.getInt(2));
+
+ if (jdbcType != null) {
+ byte[] bytes = rs.getBytes(3);
+ String val = getRawAsString(conn, bytes, jdbcType);
+ stats.setMin(val);
+ bytes = rs.getBytes(4);
+ val = getRawAsString(conn, bytes, jdbcType);
+ stats.setMax(val);
+ } else if (knownType) {
+ stats.setMin(rs.getString(3));
+ stats.setMax(rs.getString(4));
+ }
+ //if not a known conversion type (rowid, char, etc.), then we could
choose to compensate
+ }
+ } finally {
+ if(rs != null) {
+ rs.close();
+ }
+ if(stmt != null) {
+ stmt.close();
+ }
+ }
+ } catch (SQLException e) {
+ throw new TranslatorException(e);
+ }
+ return true;
+ }
+
+ /**
+ * @param colStat
+ * @param bytes
+ * @return
+ * @throws SQLException
+ */
+ private String getRawAsString( Connection conn, byte[] bytes, int type ) {
+ CallableStatement cs = null;
+ try {
+ cs = conn.prepareCall("{call dbms_stats.convert_raw_value(?, ?)}");
//$NON-NLS-1$
+ cs.registerOutParameter(2, type);
+ cs.setBytes(1, bytes);
+ cs.execute();
+ String val = cs.getString(2);
+ return val;
+ } catch (SQLException e) {
+ return null; //TODO
+ } finally {
+ if (cs != null) {
+ try {
+ cs.close();
+ } catch (SQLException e) {
+ }
+ }
+ }
+ }
+
}
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java 2011-04-15
18:12:29 UTC (rev 3094)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java 2011-04-15
20:44:09 UTC (rev 3095)
@@ -23,7 +23,6 @@
package org.teiid.dqp.internal.process;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
@@ -57,6 +56,7 @@
import org.teiid.dqp.internal.process.DQPCore.FutureWork;
import org.teiid.dqp.message.AtomicRequestMessage;
import org.teiid.dqp.message.AtomicResultsMessage;
+import org.teiid.events.EventDistributor;
import org.teiid.metadata.Table;
import org.teiid.query.function.source.XMLSystemFunctions;
import org.teiid.query.processor.relational.RelationalNodeUtil;
@@ -223,21 +223,17 @@
//check for update events
if (index == 0 && this.dtm.detectChangeEvents()) {
Command command = aqr.getCommand();
- ArrayList<String> updates = new ArrayList<String>();
int commandIndex = 0;
if (RelationalNodeUtil.isUpdate(command)) {
long ts = System.currentTimeMillis();
- checkForUpdates(results, command, updates, commandIndex, ts);
+ checkForUpdates(results, command, dtm.getEventDistributor(), commandIndex,
ts);
} else if (command instanceof BatchedUpdateCommand) {
long ts = System.currentTimeMillis();
BatchedUpdateCommand bac = (BatchedUpdateCommand)command;
for (Command uc : bac.getUpdateCommands()) {
- checkForUpdates(results, uc, updates, commandIndex++, ts);
+ checkForUpdates(results, uc, dtm.getEventDistributor(), commandIndex++, ts);
}
}
- if (this.dtm.getEventDistributor() != null && !updates.isEmpty()) {
-
this.dtm.getEventDistributor().dataModification(this.workItem.getDqpWorkContext().getVdbName(),
this.workItem.getDqpWorkContext().getVdbVersion(), updates.toArray(new
String[updates.size()]));
- }
}
} catch (TranslatorException e) {
results = exceptionOccurred(e, true);
@@ -268,7 +264,7 @@
}
private void checkForUpdates(AtomicResultsMessage results, Command command,
- ArrayList<String> updates, int commandIndex, long ts) {
+ EventDistributor distributor, int commandIndex, long ts) {
if (!RelationalNodeUtil.isUpdate(command) || !(command instanceof ProcedureContainer))
{
return;
}
@@ -286,8 +282,10 @@
return;
}
Table t = (Table)metadataId;
- updates.add(t.getFullName());
t.setLastDataModification(ts);
+ if (distributor != null) {
+ distributor.dataModification(this.workItem.getDqpWorkContext().getVdbName(),
this.workItem.getDqpWorkContext().getVdbVersion(), t.getParent().getName(), t.getName());
+ }
}
private AtomicResultsMessage asynchGet()
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2011-04-15
18:12:29 UTC (rev 3094)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2011-04-15
20:44:09 UTC (rev 3095)
@@ -60,8 +60,8 @@
import org.teiid.logging.LogManager;
import org.teiid.logging.MessageLevel;
import org.teiid.metadata.MetadataProvider;
+import org.teiid.metadata.ViewDefinition;
import org.teiid.metadata.FunctionMethod.Determinism;
-import org.teiid.metadata.MetadataProvider.ViewDefinition;
import org.teiid.query.QueryPlugin;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.eval.SecurityFunctionEvaluator;
@@ -136,9 +136,6 @@
ViewDefinition vd = metadataProvider.getViewDefinition(schema, viewName, context);
if (vd != null) {
result = new QueryNode(DataTypeManager.getCanonicalString(vd.getSql()));
- if (vd.getScope() == MetadataProvider.Scope.USER) {
- result.setUser(context.getUserName());
- }
}
qnodes.put(groupID, result);
return result;
Modified: trunk/engine/src/main/java/org/teiid/query/mapping/relational/QueryNode.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/mapping/relational/QueryNode.java 2011-04-15
18:12:29 UTC (rev 3094)
+++
trunk/engine/src/main/java/org/teiid/query/mapping/relational/QueryNode.java 2011-04-15
20:44:09 UTC (rev 3095)
@@ -44,7 +44,6 @@
// Initial state
private String query;
private List<String> bindings; // optional - construct if needed
- private String user;
// After parsing and resolution
private Command command;
private UpdateInfo updateInfo;
@@ -126,14 +125,6 @@
return query;
}
- public String getUser() {
- return user;
- }
-
- public void setUser(String user) {
- this.user = user;
- }
-
public UpdateInfo getUpdateInfo() {
return updateInfo;
}
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2011-04-15
18:12:29 UTC (rev 3094)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2011-04-15
20:44:09 UTC (rev 3095)
@@ -434,9 +434,6 @@
QueryValidatorException {
qmi = qmi.getDesignTimeMetadata();
cacheString = "transformation/" + cacheString; //$NON-NLS-1$
- if (qnode.getUser() != null) {
- cacheString += "/" + qnode.getUser(); //$NON-NLS-1$
- }
QueryNode cachedNode =
(QueryNode)qmi.getFromMetadataCache(virtualGroup.getMetadataID(), cacheString);
if (cachedNode == null
|| (qnode.getQuery() != null &&
!cachedNode.getQuery().equals(qnode.getQuery()))
@@ -474,7 +471,6 @@
}
cachedNode = new QueryNode(qnode.getQuery());
cachedNode.setCommand((Command)result.clone());
- cachedNode.setUser(qnode.getUser());
if(isView(virtualGroup, qmi)) {
String updatePlan = qmi.getUpdatePlan(virtualGroup.getMetadataID());
Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2011-04-15
18:12:29 UTC (rev 3094)
+++
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableDataManager.java 2011-04-15
20:44:09 UTC (rev 3095)
@@ -361,7 +361,7 @@
}
List<?> result = updateMatViewRow(globalStore, matTableName, tuple, delete);
if (result != null && eventDistributor != null) {
- this.eventDistributor.updateMatViewRow(context.getVdbName(), context.getVdbVersion(),
matTableName, tuple, delete);
+ this.eventDistributor.updateMatViewRow(context.getVdbName(), context.getVdbVersion(),
metadata.getName(metadata.getModelID(groupID)), metadata.getName(groupID), tuple,
delete);
}
return CollectionTupleSource.createUpdateCountTupleSource(result != null ? 1 : 0);
}
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2011-04-15
18:12:29 UTC (rev 3094)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2011-04-15
20:44:09 UTC (rev 3095)
@@ -51,6 +51,7 @@
import org.teiid.dqp.service.AutoGenDataService;
import org.teiid.dqp.service.BufferService;
import org.teiid.metadata.MetadataProvider;
+import org.teiid.metadata.ViewDefinition;
import org.teiid.query.optimizer.TestOptimizer;
import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
@@ -335,10 +336,10 @@
public ViewDefinition getViewDefinition(String schema,
String viewName, CommandContext context) {
if (callCount++ > 0) {
- ViewDefinition vd = new ViewDefinition("SELECT 'something
else'", Scope.USER);
+ ViewDefinition vd = new ViewDefinition("SELECT 'something
else'");
return vd;
}
- ViewDefinition vd = new ViewDefinition("SELECT 'hello world'",
Scope.USER);
+ ViewDefinition vd = new ViewDefinition("SELECT 'hello world'");
return vd;
}
});
Modified:
trunk/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java
===================================================================
---
trunk/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java 2011-04-15
18:12:29 UTC (rev 3094)
+++
trunk/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java 2011-04-15
20:44:09 UTC (rev 3095)
@@ -70,6 +70,7 @@
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.adminapi.impl.WorkerPoolStatisticsMetadata;
import org.teiid.adminapi.jboss.AdminProvider;
+import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.cache.CacheFactory;
import org.teiid.client.DQP;
import org.teiid.client.RequestMessage;
@@ -95,15 +96,21 @@
import org.teiid.dqp.service.SessionServiceException;
import org.teiid.dqp.service.TransactionService;
import org.teiid.events.EventDistributor;
+import org.teiid.events.EventDistributorFactory;
import org.teiid.jboss.IntegrationPlugin;
import org.teiid.logging.Log4jListener;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.logging.MessageLevel;
+import org.teiid.metadata.Column;
+import org.teiid.metadata.ColumnStats;
+import org.teiid.metadata.Schema;
import org.teiid.metadata.Table;
+import org.teiid.metadata.TableStats;
import org.teiid.net.TeiidURL;
import org.teiid.query.QueryPlugin;
import org.teiid.query.metadata.TransformationMetadata;
+import org.teiid.query.optimizer.relational.RelationalPlanner;
import org.teiid.query.tempdata.TempTableStore;
import org.teiid.security.SecurityHelper;
import org.teiid.transport.ClientServiceRegistry;
@@ -116,7 +123,7 @@
@ManagementObject(name="RuntimeEngineDeployer", isRuntime=true,
componentType=@ManagementComponent(type="teiid",subtype="dqp"),
properties=ManagementProperties.EXPLICIT)
-public class RuntimeEngineDeployer extends DQPConfiguration implements DQPManagement,
Serializable , ClientServiceRegistry, EventDistributor {
+public class RuntimeEngineDeployer extends DQPConfiguration implements DQPManagement,
Serializable , ClientServiceRegistry, EventDistributor, EventDistributorFactory {
private static final long serialVersionUID = -4676205340262775388L;
private transient SocketConfiguration jdbcSocketConfiguration;
@@ -641,8 +648,8 @@
}
@Override
- public void updateMatViewRow(String vdbName, int vdbVersion, String matViewFqn,
List<?> tuple,
- boolean delete) {
+ public void updateMatViewRow(String vdbName, int vdbVersion, String schema,
+ String viewName, List<?> tuple, boolean delete) {
VDBMetaData vdb = this.vdbRepository.getVDB(vdbName, vdbVersion);
if (vdb == null) {
return;
@@ -652,14 +659,26 @@
return;
}
try {
- this.dqpCore.getDataTierManager().updateMatViewRow(globalStore, matViewFqn, tuple,
delete);
+ this.dqpCore.getDataTierManager().updateMatViewRow(globalStore,
RelationalPlanner.MAT_PREFIX + (schema + '.' + viewName).toUpperCase(), tuple,
delete);
} catch (TeiidException e) {
LogManager.logError(LogConstants.CTX_DQP, e,
QueryPlugin.Util.getString("DQPCore.unable_to_process_event")); //$NON-NLS-1$
}
}
@Override
- public void dataModification(String vdbName, int vdbVersion, String... tableFqns) {
+ public void dataModification(String vdbName, int vdbVersion, String schema,
+ String... tableNames) {
+ updateModified(true, vdbName, vdbVersion, schema, tableNames);
+ }
+
+ @Override
+ public void schemaModification(String vdbName, int vdbVersion,
+ String schema, String... objectNames) {
+ updateModified(false, vdbName, vdbVersion, schema, objectNames);
+ }
+
+ private void updateModified(boolean data, String vdbName, int vdbVersion, String
schema,
+ String... objectNames) {
VDBMetaData vdb = this.vdbRepository.getVDB(vdbName, vdbVersion);
if (vdb == null) {
return;
@@ -668,33 +687,80 @@
if (tm == null) {
return;
}
- for (String tableFqn:tableFqns) {
- try {
- Table table = tm.getGroupID(tableFqn);
- table.setLastDataModification(System.currentTimeMillis());
- } catch (TeiidException e) {
- LogManager.logError(LogConstants.CTX_DQP, e,
QueryPlugin.Util.getString("DQPCore.unable_to_process_event")); //$NON-NLS-1$
+ try {
+ Schema s = tm.getMetadataStore().getSchema(schema.toUpperCase());
+ long ts = System.currentTimeMillis();
+ for (String name:objectNames) {
+ Table table = s.getTables().get(name);
+ if (table == null) {
+ continue;
+ }
+ if (data) {
+ table.setLastDataModification(ts);
+ } else {
+ table.setLastModified(ts);
+ }
}
+ } catch (TeiidException e) {
+ LogManager.logError(LogConstants.CTX_DQP, e,
QueryPlugin.Util.getString("DQPCore.unable_to_process_event")); //$NON-NLS-1$
}
}
@Override
- public void schemaModification(String vdbName, int vdbVersion, String... fqns) {
+ public void setColumnStats(String vdbName, int vdbVersion,
+ String schemaName, String tableName, String columnName,
+ ColumnStats stats) {
+ Table t = getTable(vdbName, vdbVersion, schemaName, tableName);
+ if (t == null) {
+ return;
+ }
+ for (Column c : t.getColumns()) {
+ if (c.getName().equalsIgnoreCase(columnName)) {
+ c.setDistinctValues(stats.getNumDistinctValues());
+ c.setNullValues(stats.getNumNullValues());
+ c.setMaximumValue(stats.getMax());
+ c.setMinimumValue(stats.getMin());
+ t.setLastModified(System.currentTimeMillis());
+ break;
+ }
+ }
+ }
+
+ @Override
+ public void setTableStats(String vdbName, int vdbVersion,
+ String schemaName, String tableName, TableStats stats) {
+ Table t = getTable(vdbName, vdbVersion, schemaName, tableName);
+ if (t == null) {
+ return;
+ }
+ t.setCardinality(stats.getCardinality());
+ t.setLastModified(System.currentTimeMillis());
+ }
+
+ private Table getTable(String vdbName, int vdbVersion, String schemaName,
+ String tableName) {
VDBMetaData vdb = this.vdbRepository.getVDB(vdbName, vdbVersion);
if (vdb == null) {
- return;
+ return null;
}
TransformationMetadata tm = vdb.getAttachment(TransformationMetadata.class);
if (tm == null) {
- return;
+ return null;
}
- for (String fqn:fqns) {
- try {
- Table table = tm.getGroupID(fqn);
- table.setLastModified(System.currentTimeMillis());
- } catch (TeiidException e) {
- LogManager.logError(LogConstants.CTX_DQP, e,
QueryPlugin.Util.getString("DQPCore.unable_to_process_event")); //$NON-NLS-1$
- }
+ Schema s;
+ try {
+ s = tm.getMetadataStore().getSchema(schemaName.toUpperCase());
+ } catch (QueryMetadataException e) {
+ LogManager.logError(LogConstants.CTX_DQP, e,
QueryPlugin.Util.getString("DQPCore.unable_to_process_event")); //$NON-NLS-1$
+ return null;
}
+ return s.getTables().get(tableName.toUpperCase());
}
+
+ public EventDistributor getEventDistributor() {
+ if (this.eventDistributor != null) {
+ return eventDistributor;
+ }
+ return this;
+ }
}