oreo-commits Mailing List for Object Relational Ooze
Brought to you by:
revusky
You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(13) |
Aug
(7) |
Sep
|
Oct
(5) |
Nov
|
Dec
(4) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
|
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(25) |
Oct
(34) |
Nov
(2) |
Dec
|
From: <re...@us...> - 2003-11-04 00:24:22
|
Update of /cvsroot/oreo/oreo/src/org/oreodata/jdbcimpl In directory sc8-pr-cvs1:/tmp/cvs-serv14452/src/org/oreodata/jdbcimpl Modified Files: JDBCConnection.java Log Message: fixing bug with nulls as part of a compount PK Index: JDBCConnection.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/jdbcimpl/JDBCConnection.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** JDBCConnection.java 16 Oct 2003 20:04:48 -0000 1.21 --- JDBCConnection.java 4 Nov 2003 00:24:16 -0000 1.22 *************** *** 188,192 **** for (int i=0; i<primaryKeyFields.length;i++) { Object pKeyField = oldRec.get(primaryKeyFields[i]); ! pstmt.setObject(index++, pKeyField); } int count = pstmt.executeUpdate(); --- 188,196 ---- for (int i=0; i<primaryKeyFields.length;i++) { Object pKeyField = oldRec.get(primaryKeyFields[i]); ! if (pKeyField == null) { ! pstmt.setNull(index++, Types.NULL); ! } else { ! pstmt.setObject(index++, pKeyField); ! } } int count = pstmt.executeUpdate(); *************** *** 217,221 **** PreparedStatement pstmt = conn.prepareStatement(buf.toString()); for (int i=0; i<pKeyFields.length; i++) { ! pstmt.setObject(i+1, primaryKey[i]); } ResultSet rs = pstmt.executeQuery(); --- 221,230 ---- PreparedStatement pstmt = conn.prepareStatement(buf.toString()); for (int i=0; i<pKeyFields.length; i++) { ! Object pkField = primaryKey[i]; ! if (pkField == null) { ! pstmt.setNull(i+1, Types.NULL); ! } else { ! pstmt.setObject(i+1, pkField); ! } } ResultSet rs = pstmt.executeQuery(); *************** *** 354,358 **** PreparedStatement pstmt = conn.prepareStatement(query.toString()); for (int i=0; i<fc.length; i++) { ! pstmt.setObject(i+1, fc[i].convertToJDBC(key[i])); } int count = pstmt.executeUpdate(); --- 363,371 ---- PreparedStatement pstmt = conn.prepareStatement(query.toString()); for (int i=0; i<fc.length; i++) { ! if (key[i] == null) { ! pstmt.setNull(i+1, Types.NULL); ! } else { ! pstmt.setObject(i+1, fc[i].convertToJDBC(key[i])); ! } } int count = pstmt.executeUpdate(); |
From: <re...@us...> - 2003-11-04 00:24:19
|
Update of /cvsroot/oreo/oreo/examples/simple In directory sc8-pr-cvs1:/tmp/cvs-serv14452/examples/simple Modified Files: HelloOreo.java recorddefs.xml Log Message: fixing bug with nulls as part of a compount PK Index: HelloOreo.java =================================================================== RCS file: /cvsroot/oreo/oreo/examples/simple/HelloOreo.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** HelloOreo.java 6 Oct 2003 15:39:29 -0000 1.6 --- HelloOreo.java 4 Nov 2003 00:24:16 -0000 1.7 *************** *** 1,4 **** --- 1,5 ---- import org.oreodata.*; import org.oreodata.metadata.MetadataLoader; + import org.oreodata.sql.Select; import java.util.List; import java.util.Iterator; *************** *** 13,25 **** static DataRegistry registry; static OreoDataSource data; static public void main(String[] args) { int exitCode = 0; try { - long t = System.currentTimeMillis(); init(); ! System.err.println(System.currentTimeMillis() -t); ! insertData("John", "Smith"); ! insertData("Mary", "Roberts"); outputData(); } --- 14,24 ---- static DataRegistry registry; static OreoDataSource data; + static List results; static public void main(String[] args) { int exitCode = 0; try { init(); ! results = data.select(args[0]); outputData(); } *************** *** 43,66 **** /** - * Code to insert a record into our container. - */ - static public void insertData(String firstName, String lastName) throws IOException { - Record rec = registry.getExemplar("simple_entry"); - rec.set("first_name", firstName); - rec.set("last_name", lastName); - data.insert(rec); - } - - /** * Code that simply runs over the records in the container * and outputs them to the console. */ static public void outputData() throws IOException { ! // List recs = data.select("SELECT * FROM simple_entry WHERE UPPER(first_name)='MARY' ORDER BY last_name DESC"); ! List recs = data.select("SELECT CONCAT(first_name, ' ', last_name) as name FROM simple_entry WHERE name='John Smith' ORDER BY last_name DESC"); ! for (Iterator it = recs.iterator(); it.hasNext();) { ! Record rec = (Record) it.next(); ! System.out.println("\nFirst name: " + rec.get("first_name")); ! System.out.println("Last name: " + rec.get("last_name")); } } --- 42,55 ---- /** * Code that simply runs over the records in the container * and outputs them to the console. */ static public void outputData() throws IOException { ! for (Iterator it = results.iterator(); it.hasNext();) { ! Tuple tup = (Tuple) it.next(); ! System.out.println("\nFirst column: " + tup.get(0)); ! System.out.println("First name: " + tup.get("first_name")); ! // System.out.println("maxi: " + tup.get("maxi")); ! // System.out.println("Salary: " + tup.get("salary")); } } Index: recorddefs.xml =================================================================== RCS file: /cvsroot/oreo/oreo/examples/simple/recorddefs.xml,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** recorddefs.xml 28 Sep 2003 23:35:48 -0000 1.4 --- recorddefs.xml 4 Nov 2003 00:24:16 -0000 1.5 *************** *** 2,11 **** <!DOCTYPE RECORDDEFS SYSTEM "org/oreodata/metadata/recorddefs.dtd"> <RECORDDEFS> ! <RECORD TYPE = "simple_entry" PRIMARY_KEY="unique_id" > ! <FIELD NAME="unique_id" CLASS="&NUMBER;" REQUIRED="Y" > ! <PROPERTY KEY="TYPE" VALUE="INTEGER" /> ! </FIELD> ! <FIELD NAME="first_name" CLASS="&STRING;" REQUIRED="Y" /> <FIELD NAME="last_name" CLASS="&STRING;" REQUIRED="Y" /> </RECORD> </RECORDDEFS> --- 2,12 ---- <!DOCTYPE RECORDDEFS SYSTEM "org/oreodata/metadata/recorddefs.dtd"> <RECORDDEFS> ! <RECORD TYPE = "simple_entry" PRIMARY_KEY="last_name,first_name" > <FIELD NAME="last_name" CLASS="&STRING;" REQUIRED="Y" /> + <FIELD NAME="first_name" CLASS="&STRING;" REQUIRED="Y" /> + <FIELD NAME="salary" CLASS="&NUMBER;" REQUIRED="N"> + <PROPERTY KEY="TYPE" VALUE="INTEGER"/> + <PROPERTY KEY="MIN" VALUE="0"/> + </FIELD> </RECORD> </RECORDDEFS> |
From: <dmi...@us...> - 2003-10-20 04:14:21
|
Update of /cvsroot/oreo/oreo In directory sc8-pr-cvs1:/tmp/cvs-serv6047 Modified Files: build.xml Log Message: Added build.properties support for ./ and user home dirs for setting JavaCC home -- hopefully, it will expand a bit for compiler and options. Index: build.xml =================================================================== RCS file: /cvsroot/oreo/oreo/build.xml,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** build.xml 6 Oct 2003 15:39:28 -0000 1.10 --- build.xml 19 Oct 2003 22:58:50 -0000 1.11 *************** *** 1,4 **** --- 1,7 ---- <!DOCTYPE project []> <project name="oreo" default="build"> + <property file="build.properties"/> + <property file="${user.home}/build.properties"/> + <!-- Ant build file for the Oreo project *************** *** 16,19 **** --- 19,23 ---- <property name="distrofilename" value="oreo0_1.tar.gz" /> <property name="build.classes.dir" value="./build/classes" /> + <property name="javacchome" value="/shared/javalibs/javacc" /> <path id="oreo.classpath"> *************** *** 28,32 **** target="src/org/oreodata/sql/SQLParser.jj" outputdirectory="src/org/oreodata/sql" ! javacchome="/shared/javalibs/javacc" /> </target> --- 32,36 ---- target="src/org/oreodata/sql/SQLParser.jj" outputdirectory="src/org/oreodata/sql" ! javacchome="${javacchome}" /> </target> |
From: <re...@us...> - 2003-10-19 18:43:26
|
Update of /cvsroot/oreo/oreo/src/org/oreodata/sql In directory sc8-pr-cvs1:/tmp/cvs-serv24955 Added Files: ParseException.java Log Message: making ParseException unchecked --- NEW FILE: ParseException.java --- /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 2.1 */ package org.oreodata.sql; /** * This exception is thrown when parse errors are encountered. * You can explicitly create objects of this exception type by * calling the method generateParseException in the generated * parser. * * You can modify this class to customize your error reporting * mechanisms so long as you retain the public fields. */ public class ParseException extends RuntimeException { /** * This constructor is used by the method "generateParseException" * in the generated parser. Calling this constructor generates * a new object of this type with the fields "currentToken", * "expectedTokenSequences", and "tokenImage" set. The boolean * flag "specialConstructor" is also set to true to indicate that * this constructor was used to create this object. * This constructor calls its super class with the empty string * to force the "toString" method of parent class "Throwable" to * print the error message in the form: * ParseException: <result of getMessage> */ public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, String[] tokenImageVal ) { super(""); specialConstructor = true; currentToken = currentTokenVal; expectedTokenSequences = expectedTokenSequencesVal; tokenImage = tokenImageVal; } /** * The following constructors are for use by you for whatever * purpose you can think of. Constructing the exception in this * manner makes the exception behave in the normal way - i.e., as * documented in the class "Throwable". The fields "errorToken", * "expectedTokenSequences", and "tokenImage" do not contain * relevant information. The JavaCC generated code does not use * these constructors. */ public ParseException() { super(); specialConstructor = false; } public ParseException(String message) { super(message); specialConstructor = false; } /** * This variable determines which constructor was used to create * this object and thereby affects the semantics of the * "getMessage" method (see below). */ protected boolean specialConstructor; /** * This is the last token that has been consumed successfully. If * this object has been created due to a parse error, the token * followng this token will (therefore) be the first error token. */ public Token currentToken; /** * Each entry in this array is an array of integers. Each array * of integers represents a sequence of tokens (by their ordinal * values) that is expected at this point of the parse. */ public int[][] expectedTokenSequences; /** * This is a reference to the "tokenImage" array of the generated * parser within which the parse error occurred. This array is * defined in the generated ...Constants interface. */ public String[] tokenImage; /** * This method has the standard behavior when this object has been * created using the standard constructors. Otherwise, it uses * "currentToken" and "expectedTokenSequences" to generate a parse * error message and returns it. If this object has been created * due to a parse error, and you do not catch it (it gets thrown * from the parser), then this method is called during the printing * of the final stack trace, and hence the correct error message * gets displayed. */ public String getMessage() { if (!specialConstructor) { return super.getMessage(); } String expected = ""; int maxSize = 0; for (int i = 0; i < expectedTokenSequences.length; i++) { if (maxSize < expectedTokenSequences[i].length) { maxSize = expectedTokenSequences[i].length; } for (int j = 0; j < expectedTokenSequences[i].length; j++) { expected += tokenImage[expectedTokenSequences[i][j]] + " "; } if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { expected += "..."; } expected += eol + " "; } String retval = "Encountered \""; Token tok = currentToken.next; for (int i = 0; i < maxSize; i++) { if (i != 0) retval += " "; if (tok.kind == 0) { retval += tokenImage[0]; break; } retval += add_escapes(tok.image); tok = tok.next; } retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; retval += "." + eol; if (expectedTokenSequences.length == 1) { retval += "Was expecting:" + eol + " "; } else { retval += "Was expecting one of:" + eol + " "; } retval += expected; return retval; } /** * The end of line string for this machine. */ protected String eol = System.getProperty("line.separator", "\n"); /** * Used to convert raw characters to their escaped version * when these raw version cannot be used as part of an ASCII * string literal. */ protected String add_escapes(String str) { StringBuffer retval = new StringBuffer(); char ch; for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) { case 0 : continue; case '\b': retval.append("\\b"); continue; case '\t': retval.append("\\t"); continue; case '\n': retval.append("\\n"); continue; case '\f': retval.append("\\f"); continue; case '\r': retval.append("\\r"); continue; case '\"': retval.append("\\\""); continue; case '\'': retval.append("\\\'"); continue; case '\\': retval.append("\\\\"); continue; default: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { String s = "0000" + Integer.toString(ch, 16); retval.append("\\u" + s.substring(s.length() - 4, s.length())); } else { retval.append(ch); } continue; } } return retval.toString(); } } |
From: <re...@us...> - 2003-10-19 15:59:57
|
Update of /cvsroot/oreo/oreo/src/org/oreodata In directory sc8-pr-cvs1:/tmp/cvs-serv30764 Added Files: Tuple.java Log Message: forgot Tuple.java --- NEW FILE: Tuple.java --- /* OREO Object-relational layer Copyright (c) 2001, Jonathan Revusky, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the names of the project contributors nor any of the names "Niggle", "OREO", or "Object-Relational Ooze" may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package org.oreodata; public interface Tuple { /** * Method to get the value of a field by name. * Subclasses may wrap this * with a higher-level get/set API. * @param fieldname * @throws InvalidFieldException if there is no field of that name. */ Object get(String fieldname); /** * @return the field value of this tuple by integer index (zero-based) */ Object get(int i); /** * The number of fields in the record. */ int size(); } |
From: <re...@us...> - 2003-10-16 20:04:55
|
Update of /cvsroot/oreo/oreo/src/org/oreodata In directory sc8-pr-cvs1:/tmp/cvs-serv27301 Modified Files: AbstractDataSource.java Log Message: correcting missing import Index: AbstractDataSource.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/AbstractDataSource.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** AbstractDataSource.java 10 Oct 2003 14:47:26 -0000 1.15 --- AbstractDataSource.java 16 Oct 2003 20:04:48 -0000 1.16 *************** *** 337,352 **** } - public List select(String query) throws IOException { - if (query == null) { - return select((RecordFilter) null); - } - Select select = new Select(query); - RecordComparator comparator = select.asComparator(); - List result = select(select, comparator); - select.setEntities(result); - // select.handleGroupBy(); // currently unimplemented - return select.getEntities(); - } - public Record insert(Record rec) throws IOException { throw new UnsupportedOperationException(); --- 337,340 ---- |
From: <re...@us...> - 2003-10-16 20:04:55
|
Update of /cvsroot/oreo/oreo/src/org/oreodata/jdbcimpl In directory sc8-pr-cvs1:/tmp/cvs-serv27301/jdbcimpl Modified Files: JDBCBackedRecordSet.java JDBCConnection.java Log Message: correcting missing import Index: JDBCBackedRecordSet.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/jdbcimpl/JDBCBackedRecordSet.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** JDBCBackedRecordSet.java 28 Sep 2003 23:35:48 -0000 1.17 --- JDBCBackedRecordSet.java 16 Oct 2003 20:04:48 -0000 1.18 *************** *** 41,44 **** --- 41,45 ---- import org.oreodata.*; import org.oreodata.predicates.*; + import org.oreodata.sql.Select; import org.oreodata.util.*; *************** *** 508,511 **** --- 509,526 ---- return result; } + + public List select(String query) throws IOException { + if (query == null) { + return select((RecordFilter) null); + } + Select select = new Select(query); + RecordComparator comparator = select.asComparator(); + return select(select, comparator); + // select.setEntities(result); + // select.handleGroupBy(); // currently unimplemented + // return select.getEntities(); + } + + protected JDBCConnection getConnection() { Index: JDBCConnection.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/jdbcimpl/JDBCConnection.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** JDBCConnection.java 5 Oct 2003 18:14:42 -0000 1.20 --- JDBCConnection.java 16 Oct 2003 20:04:48 -0000 1.21 *************** *** 38,41 **** --- 38,42 ---- import org.oreodata.predicates.Predicates; import org.oreodata.predicates.SQLQueryUtil; + import org.oreodata.sql.*; /** |
Update of /cvsroot/oreo/oreo/src/org/oreodata/sql In directory sc8-pr-cvs1:/tmp/cvs-serv20995 Modified Files: AggregateFunction.java AggregateFunctionCall.java Column.java ComparisonExpression.java Select.java Statement.java Log Message: tweak to treatment of column references, finished off GROUP BY stuff, seems to work Index: AggregateFunction.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/AggregateFunction.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AggregateFunction.java 10 Oct 2003 14:47:26 -0000 1.3 --- AggregateFunction.java 14 Oct 2003 22:59:27 -0000 1.4 *************** *** 18,23 **** public Number evaluate(Expression exp, List entities) { Number min = null; ! for (int i=0; i<entities.size(); i++) { ! Number N = exp.getNumericalValue((Tuple) entities.get(i)); if (N != null) { if (min == null || ((Comparable) min).compareTo(N) >0) { --- 18,24 ---- public Number evaluate(Expression exp, List entities) { Number min = null; ! for (Iterator it = entities.iterator(); it.hasNext();) { ! Tuple tuple = (Tuple) it.next(); ! Number N = exp.getNumericalValue(tuple); if (N != null) { if (min == null || ((Comparable) min).compareTo(N) >0) { *************** *** 33,38 **** public Number evaluate(Expression exp, List entities) { Number max = null; ! for (int i=0; i<entities.size(); i++) { ! Number N = exp.getNumericalValue((Tuple) entities.get(i)); if (N != null) { if (max == null || ((Comparable) max).compareTo(N) <0) { --- 34,40 ---- public Number evaluate(Expression exp, List entities) { Number max = null; ! for (Iterator it = entities.iterator(); it.hasNext();) { ! Tuple tuple = (Tuple) it.next(); ! Number N = exp.getNumericalValue(tuple); if (N != null) { if (max == null || ((Comparable) max).compareTo(N) <0) { *************** *** 49,54 **** double sum = 0d; int nonNullItems = 0; ! for (int i=0; i<entities.size(); i++) { ! Tuple tuple = (Tuple) entities.get(i); Number value = exp.getNumericalValue(tuple); if (value != null) { --- 51,56 ---- double sum = 0d; int nonNullItems = 0; ! for (Iterator it = entities.iterator(); it.hasNext();) { ! Tuple tuple = (Tuple) it.next(); Number value = exp.getNumericalValue(tuple); if (value != null) { *************** *** 64,69 **** public Number evaluate(Expression exp, List entities) { double sum = 0d; ! for (int i=0; i<entities.size(); i++) { ! Tuple tuple = (Tuple) entities.get(i); Number value = exp.getNumericalValue(tuple); if (value != null) { --- 66,71 ---- public Number evaluate(Expression exp, List entities) { double sum = 0d; ! for (Iterator it = entities.iterator(); it.hasNext();) { ! Tuple tuple = (Tuple) it.next(); Number value = exp.getNumericalValue(tuple); if (value != null) { Index: AggregateFunctionCall.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/AggregateFunctionCall.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** AggregateFunctionCall.java 11 Oct 2003 18:11:10 -0000 1.6 --- AggregateFunctionCall.java 14 Oct 2003 22:59:29 -0000 1.7 *************** *** 52,57 **** if (arg != null) { items = new ArrayList(); ! for (int i=0; i<tuples.size(); i++) { ! Tuple tup = (Tuple) tuples.get(i); Object val = arg.getValue(tup); if (val != null) { --- 52,57 ---- if (arg != null) { items = new ArrayList(); ! for (Iterator it = tuples.iterator(); it.hasNext();) { ! Tuple tup = (Tuple) it.next(); Object val = arg.getValue(tup); if (val != null) { Index: Column.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Column.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Column.java 11 Oct 2003 18:51:23 -0000 1.6 --- Column.java 14 Oct 2003 22:59:29 -0000 1.7 *************** *** 89,92 **** --- 89,96 ---- name = (String) aliased; } + } else { + String recName = ((Record) tuple).getType(); + Assert.asert(recName.equals(this.recName), + recName + " is not the same as " + this.recName); } } Index: ComparisonExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/ComparisonExpression.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ComparisonExpression.java 11 Oct 2003 18:11:10 -0000 1.6 --- ComparisonExpression.java 14 Oct 2003 22:59:29 -0000 1.7 *************** *** 20,24 **** NOT_LIKE = 7; ! static final String[] operators = new String[] {"=", "!=", ">", "<", ">=", "<="}; --- 20,24 ---- NOT_LIKE = 7; ! static final String[] operators = new String[] {"=", "!=", ">", "<", ">=", "<=", "LIKE", "NOT LIKE"}; Index: Select.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Select.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Select.java 11 Oct 2003 18:51:23 -0000 1.8 --- Select.java 14 Oct 2003 22:59:29 -0000 1.9 *************** *** 68,72 **** buf.append(alias); } ! for (int i=0; i<supplementalTables.size(); i++) { buf.append(", "); String recName = (String) supplementalTables.get(i); --- 68,73 ---- buf.append(alias); } ! int suppTableSize = supplementalTables == null ? 0 : supplementalTables.size(); ! for (int i=0; i<suppTableSize; i++) { buf.append(", "); String recName = (String) supplementalTables.get(i); *************** *** 242,247 **** } else { boolean keep = false; ! for (int i=0; i<tuples.size(); i++) { ! Tuple tup = (Tuple) tuples.get(i); Boolean B = having.getBooleanValue(tup); if (B != null && B.booleanValue()) { --- 243,248 ---- } else { boolean keep = false; ! for (Iterator it = tuples.iterator(); it.hasNext();) { ! Tuple tup = (Tuple) it.next(); Boolean B = having.getBooleanValue(tup); if (B != null && B.booleanValue()) { *************** *** 311,316 **** } else { keepGroup = false; ! for (int i=0; i<tuples.size(); i++) { ! Tuple tup = (Tuple) tuples.get(i); Boolean B = having.getBooleanValue(tup); if (B != null && B.booleanValue()) { --- 312,317 ---- } else { keepGroup = false; ! for (Iterator iter = tuples.iterator(); iter.hasNext();) { ! Tuple tup = (Tuple) iter.next(); Boolean B = having.getBooleanValue(tup); if (B != null && B.booleanValue()) { *************** *** 338,343 **** entities.add(row); } else { ! for (int i=0; i<entities.size(); i++) { ! Tuple row = new SelectedRow((Tuple) entities.get(i)); entities.set(i, row); } --- 339,344 ---- entities.add(row); } else { ! for (int i = 0; i<entities.size(); i++) { ! Tuple row = (Tuple) entities.get(i); entities.set(i, row); } *************** *** 376,381 **** List result = new ArrayList(); HashSet set = new HashSet(); ! for (int i=0; i< items.size(); i++) { ! Object item = items.get(i); if (!set.contains(item)) { set.add(item); --- 377,382 ---- List result = new ArrayList(); HashSet set = new HashSet(); ! for (Iterator it = items.iterator(); it.hasNext();) { ! Object item = it.next(); if (!set.contains(item)) { set.add(item); *************** *** 384,387 **** --- 385,392 ---- } return result; + } + + public boolean hasSelectList() { + return selectList != null; } } Index: Statement.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Statement.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Statement.java 11 Oct 2003 18:11:10 -0000 1.6 --- Statement.java 14 Oct 2003 22:59:29 -0000 1.7 *************** *** 43,50 **** public void setEntities(List entities) { this.entities = entities; - for (int i=0; i<aggregateFunctions.size(); i++) { - AggregateFunctionCall afc = (AggregateFunctionCall) aggregateFunctions.get(i); - Object val = afc.getValue(null); - } } --- 43,46 ---- *************** *** 62,70 **** void calculateAggregates() { ! for (int i=0; i<aggregateFunctions.size(); i++) { ! AggregateFunctionCall afc = (AggregateFunctionCall) aggregateFunctions.get(i); Number aggVal = afc.evaluate(entities); cacheAggResult(afc, aggVal); } } } --- 58,70 ---- void calculateAggregates() { ! for (Iterator it = aggregateFunctions.iterator(); it.hasNext();) { ! AggregateFunctionCall afc = (AggregateFunctionCall) it.next(); Number aggVal = afc.evaluate(entities); cacheAggResult(afc, aggVal); } + } + + public String getReferencedTable() { + return referencedTable; } } |
From: <re...@us...> - 2003-10-11 18:58:36
|
Update of /cvsroot/oreo/oreo/src/org/oreodata In directory sc8-pr-cvs1:/tmp/cvs-serv20285 Modified Files: AbstractRecord.java Record.java Log Message: adding a size() to Tuple Index: AbstractRecord.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/AbstractRecord.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** AbstractRecord.java 10 Oct 2003 14:47:26 -0000 1.6 --- AbstractRecord.java 11 Oct 2003 18:58:29 -0000 1.7 *************** *** 457,462 **** abstract void setImmutable(boolean b); - // abstract protected Object get(int i); - abstract public void set(int i, Object value); } --- 457,464 ---- abstract void setImmutable(boolean b); abstract public void set(int i, Object value); + + public int size() { + return getMetadata().size(); + } } Index: Record.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/Record.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Record.java 10 Oct 2003 14:47:26 -0000 1.5 --- Record.java 11 Oct 2003 18:58:29 -0000 1.6 *************** *** 217,220 **** --- 217,221 ---- */ boolean hasChildren() throws MissingContextException; + } |
From: <re...@us...> - 2003-10-11 18:58:36
|
Update of /cvsroot/oreo/oreo/src/org/oreodata/ref In directory sc8-pr-cvs1:/tmp/cvs-serv20285/ref Modified Files: RecordProxy.java Log Message: adding a size() to Tuple Index: RecordProxy.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/ref/RecordProxy.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RecordProxy.java 10 Oct 2003 14:47:26 -0000 1.5 --- RecordProxy.java 11 Oct 2003 18:58:30 -0000 1.6 *************** *** 127,130 **** --- 127,134 ---- return getUnderlyingRecord().get(i); } + + public int size() { + return getUnderlyingRecord().size(); + } public boolean equals(Object o) { |
From: <re...@us...> - 2003-10-11 18:58:36
|
Update of /cvsroot/oreo/oreo/src/org/oreodata/util In directory sc8-pr-cvs1:/tmp/cvs-serv20285/util Modified Files: Util.java Log Message: adding a size() to Tuple Index: Util.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/util/Util.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Util.java 28 Sep 2003 23:35:48 -0000 1.6 --- Util.java 11 Oct 2003 18:58:30 -0000 1.7 *************** *** 492,494 **** --- 492,508 ---- static Random rnd = new Random(); + + static public int compareNumbers(Number first, Number second) { + if (first.getClass() == second.getClass()) { + return ((Comparable) first).compareTo((Comparable) second); + } + double diff = first.doubleValue() - second.doubleValue(); + if (diff <0d) { + return -1; + } + if (diff >0d) { + return 1; + } + return 0; + } } |
From: <re...@us...> - 2003-10-11 18:51:26
|
Update of /cvsroot/oreo/oreo/src/org/oreodata/sql In directory sc8-pr-cvs1:/tmp/cvs-serv19242 Modified Files: Column.java OrderByClause.java Select.java Log Message: aggregates with GROUP BY and HAVING seem to be working Index: Column.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Column.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Column.java 11 Oct 2003 18:11:10 -0000 1.5 --- Column.java 11 Oct 2003 18:51:23 -0000 1.6 *************** *** 69,84 **** Object getValue(Tuple tuple) { - checkAliases(); - String name = this.name; - if (tableName == null) { - // check if this is an alias. - Object aliased = stmt.aliases.get(name); - if (aliased != null) { - if (aliased instanceof Expression) { - return ((Expression) aliased).getValue(tuple); - } - name = (String) aliased; - } - } if (tuple == null) { //This is annoyingly kludgy. --- 69,72 ---- *************** *** 87,90 **** --- 75,92 ---- Object val = m.get(this.name); return val; + } + } + if (tuple instanceof Record) { + checkAliases(); + String name = this.name; + if (tableName == null) { + // check if this is an alias. + Object aliased = stmt.aliases.get(name); + if (aliased != null) { + if (aliased instanceof Expression) { + return ((Expression) aliased).getValue(tuple); + } + name = (String) aliased; + } } } Index: OrderByClause.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/OrderByClause.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** OrderByClause.java 11 Oct 2003 18:11:10 -0000 1.3 --- OrderByClause.java 11 Oct 2003 18:51:23 -0000 1.4 *************** *** 48,55 **** } if (val1 == null) { ! return reverse; } if (val2 == null) { ! return -1 *reverse; } int result = val1.compareTo(val2); --- 48,55 ---- } if (val1 == null) { ! return -1*reverse; } if (val2 == null) { ! return reverse; } int result = val1.compareTo(val2); Index: Select.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Select.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Select.java 11 Oct 2003 18:11:10 -0000 1.7 --- Select.java 11 Oct 2003 18:51:23 -0000 1.8 *************** *** 222,226 **** ((List) groupByMap.get(al)).add(tuple); } ! applyHaving(); } --- 222,226 ---- ((List) groupByMap.get(al)).add(tuple); } ! // applyHaving(); } *************** *** 301,305 **** row.add(exp.getValue(null)); } ! groupedRows.add(row); this.currentGroupBy = null; this.currentGroupByValues = null; --- 301,327 ---- row.add(exp.getValue(null)); } ! boolean keepGroup = true; ! if (having != null) { ! List tuples = (List) groupByMap.get(currentGroupBy); ! if (having.isScalar()) { ! Boolean B = having.getBooleanValue(null); ! if (B == null || !B.booleanValue()) { ! keepGroup = false; ! } ! } else { ! keepGroup = false; ! for (int i=0; i<tuples.size(); i++) { ! Tuple tup = (Tuple) tuples.get(i); ! Boolean B = having.getBooleanValue(tup); ! if (B != null && B.booleanValue()) { ! keepGroup = true; ! break; ! } ! } ! } ! } ! if (keepGroup) { ! groupedRows.add(row); ! } this.currentGroupBy = null; this.currentGroupByValues = null; |
Update of /cvsroot/oreo/oreo/src/org/oreodata/sql In directory sc8-pr-cvs1:/tmp/cvs-serv14011 Modified Files: AggregateFunctionCall.java AndExpression.java Column.java ComparisonExpression.java Expression.java FunctionCall.java NotCondition.java NullComparison.java NumberLiteral.java OrExpression.java OrderByClause.java Parenthesis.java SQLParser.jj Select.java Statement.java UnaryExpression.java Log Message: implementing group by (not quite finished) Index: AggregateFunctionCall.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/AggregateFunctionCall.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AggregateFunctionCall.java 10 Oct 2003 14:47:26 -0000 1.5 --- AggregateFunctionCall.java 11 Oct 2003 18:11:10 -0000 1.6 *************** *** 43,51 **** Object getValue(Tuple tuple) { // We are assuming here that all aggregates have already been calculated and cached. ! return stmt.getCachedAggResult(this, tuple); } Number evaluate(List tuples) { ! return aggfunc.evaluate(arg, tuples); } --- 43,68 ---- Object getValue(Tuple tuple) { // We are assuming here that all aggregates have already been calculated and cached. ! return stmt.getCachedAggResult(this); } Number evaluate(List tuples) { ! List items = tuples; ! if (aggfunc == AggregateFunction.COUNT) { ! // Kludgy, but we deal with COUNT specially here. ! if (arg != null) { ! items = new ArrayList(); ! for (int i=0; i<tuples.size(); i++) { ! Tuple tup = (Tuple) tuples.get(i); ! Object val = arg.getValue(tup); ! if (val != null) { ! items.add(val); ! } ! } ! } ! if (distinct) { ! items = Select.removeDuplicates(items); ! } ! } ! return aggfunc.evaluate(arg, items); } Index: AndExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/AndExpression.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AndExpression.java 10 Oct 2003 14:47:26 -0000 1.3 --- AndExpression.java 11 Oct 2003 18:11:10 -0000 1.4 *************** *** 36,38 **** --- 36,46 ---- return left.isScalar() && right.isScalar(); } + + public boolean equals(Object obj) { + if (obj instanceof AndExpression) { + AndExpression other = (AndExpression) obj; + return left.equals(other.left) && right.equals(other.right); + } + return false; + } } Index: Column.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Column.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Column.java 10 Oct 2003 14:47:26 -0000 1.4 --- Column.java 11 Oct 2003 18:11:10 -0000 1.5 *************** *** 81,88 **** --- 81,103 ---- } } + if (tuple == null) { + //This is annoyingly kludgy. + if (stmt instanceof Select) { + Map m = ((Select) stmt).currentGroupByValues; + Object val = m.get(this.name); + return val; + } + } return tuple.get(name); } boolean isScalar() { + return false; + } + + public boolean equals(Object obj) { + if (obj instanceof Column) { + return name.equals(((Column) obj).name); + } return false; } Index: ComparisonExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/ComparisonExpression.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ComparisonExpression.java 10 Oct 2003 15:53:44 -0000 1.5 --- ComparisonExpression.java 11 Oct 2003 18:11:10 -0000 1.6 *************** *** 69,71 **** --- 69,79 ---- return left.isScalar() && right.isScalar(); } + + public boolean equals(Object obj) { + if (obj instanceof ComparisonExpression) { + ComparisonExpression other = (ComparisonExpression) obj; + return operator == other.operator && left.equals(other.left) && right.equals(other.right); + } + return false; + } } Index: Expression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Expression.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Expression.java 10 Oct 2003 15:53:44 -0000 1.5 --- Expression.java 11 Oct 2003 18:11:10 -0000 1.6 *************** *** 21,24 **** --- 21,27 ---- Number getNumericalValue(Tuple tuple) { Object val = getValue(tuple); + if (val == null) { + return null; + } if (val instanceof Number) { return (Number) val; Index: FunctionCall.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/FunctionCall.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** FunctionCall.java 10 Oct 2003 14:47:26 -0000 1.6 --- FunctionCall.java 11 Oct 2003 18:11:10 -0000 1.7 *************** *** 58,60 **** --- 58,68 ---- return false; // REVISIT } + + public boolean equals(Object obj) { + if (obj instanceof FunctionCall) { + FunctionCall other = (FunctionCall) obj; + return functionName.equals(other.functionName) && args.equals(other.args); + } + return false; + } } Index: NotCondition.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/NotCondition.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NotCondition.java 10 Oct 2003 14:47:26 -0000 1.3 --- NotCondition.java 11 Oct 2003 18:11:10 -0000 1.4 *************** *** 27,29 **** --- 27,37 ---- return condition.isScalar(); } + + public boolean equals(Object obj) { + if (obj instanceof NotCondition) { + NotCondition other = (NotCondition) obj; + return other.condition.equals(condition); + } + return false; + } } Index: NullComparison.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/NullComparison.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** NullComparison.java 10 Oct 2003 14:47:26 -0000 1.4 --- NullComparison.java 11 Oct 2003 18:11:10 -0000 1.5 *************** *** 31,33 **** --- 31,41 ---- return exp.isScalar(); } + + public boolean equals(Object obj) { + if (obj instanceof NullComparison) { + NullComparison other = (NullComparison) obj; + return not == other.not && exp.equals(other.exp); + } + return false; + } } Index: NumberLiteral.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/NumberLiteral.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NumberLiteral.java 10 Oct 2003 14:47:26 -0000 1.3 --- NumberLiteral.java 11 Oct 2003 18:11:10 -0000 1.4 *************** *** 25,27 **** --- 25,35 ---- return true; } + + public boolean equals(Object obj) { + if (obj instanceof NumberLiteral) { + NumberLiteral other = (NumberLiteral) obj; + return other.value.doubleValue() == value.doubleValue(); + } + return false; + } } Index: OrExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/OrExpression.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** OrExpression.java 10 Oct 2003 14:47:26 -0000 1.3 --- OrExpression.java 11 Oct 2003 18:11:10 -0000 1.4 *************** *** 36,38 **** --- 36,46 ---- return left.isScalar() && right.isScalar(); } + + public boolean equals(Object obj) { + if (obj instanceof OrExpression) { + OrExpression other = (OrExpression) obj; + return left.equals(other.left) && right.equals(other.right); + } + return false; + } } Index: OrderByClause.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/OrderByClause.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** OrderByClause.java 10 Oct 2003 14:47:26 -0000 1.2 --- OrderByClause.java 11 Oct 2003 18:11:10 -0000 1.3 *************** *** 43,58 **** Comparable val1 = (Comparable) items[i].getValue((Tuple) first); Comparable val2 = (Comparable) items[i].getValue((Tuple) second); if (val1 == null && val2 == null) { ! return -1; } if (val1 == null) { ! return 1; } if (val2 == null) { ! return -1; } int result = val1.compareTo(val2); if (result != 0) { ! return desc[i] ? -1*result : result; } } --- 43,59 ---- Comparable val1 = (Comparable) items[i].getValue((Tuple) first); Comparable val2 = (Comparable) items[i].getValue((Tuple) second); + int reverse = desc[i] ? -1 : 1; if (val1 == null && val2 == null) { ! continue; } if (val1 == null) { ! return reverse; } if (val2 == null) { ! return -1 *reverse; } int result = val1.compareTo(val2); if (result != 0) { ! return result*reverse; } } Index: Parenthesis.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Parenthesis.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Parenthesis.java 10 Oct 2003 14:47:26 -0000 1.3 --- Parenthesis.java 11 Oct 2003 18:11:10 -0000 1.4 *************** *** 24,26 **** --- 24,37 ---- return nestedExpression.isScalar(); } + + public boolean equals(Object obj) { + if (obj instanceof Parenthesis) { + return ((Parenthesis) obj).nestedExpression.equals(nestedExpression); + } + if (obj instanceof Expression) { + return ((Expression) obj).equals(nestedExpression); + } + return false; + } + } Index: SQLParser.jj =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/SQLParser.jj,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** SQLParser.jj 10 Oct 2003 14:47:26 -0000 1.8 --- SQLParser.jj 11 Oct 2003 18:11:10 -0000 1.9 *************** *** 186,189 **** --- 186,190 ---- List selectList, fromList; Expression where=null, exp; + Column column; OrderByClause orderByClause=null; } *************** *** 191,194 **** --- 192,196 ---- {position = 0;} <SELECT> + [<DISTINCT> {select.distinct = true;}] ( <STAR> *************** *** 215,222 **** [ <GROUP_BY> {select.groupByList = new ArrayList();} ! exp=Expression(select) {select.groupByList.add(exp);} ( <COMMA> ! exp=Expression(select) {select.groupByList.add(exp);} )* [<HAVING> select.having = Expression(select)] --- 217,224 ---- [ <GROUP_BY> {select.groupByList = new ArrayList();} ! column=Column(select) {select.groupByList.add(column);} ( <COMMA> ! column=Column(select) {select.groupByList.add(column);} )* [<HAVING> select.having = Expression(select)] *************** *** 233,241 **** } { ! item=Expression(select) {select.addSelectItem(item);} [ [<AS>] ! alias=<IDENTIFIER> {select.addAlias(alias.image, item);} ] } --- 235,247 ---- } { ! item=Expression(select) [ [<AS>] ! alias=<IDENTIFIER> ] + { + String aliasName = alias == null ? null : alias.image; + select.addSelectItem(item, aliasName); + } } Index: Select.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Select.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Select.java 10 Oct 2003 14:47:26 -0000 1.6 --- Select.java 11 Oct 2003 18:11:10 -0000 1.7 *************** *** 12,15 **** --- 12,16 ---- public class Select extends Statement implements RecordFilter { + boolean distinct; List selectList; // If this is null, it's just a "select * ...", otherwise a list of expressions List groupByList; // The expressions in the GROUP BY Clause. This may be null *************** *** 17,21 **** --- 18,26 ---- OrderByClause orderByClause; // An object representing the ORDER BY clause, may be null. + Map selectColumnNames; Map groupByMap; + + Map currentGroupByValues; // This is only non-null when we are processing a group-by + List currentGroupBy; *************** *** 97,105 **** } ! void addSelectItem(Expression exp) { if (selectList == null) { selectList = new ArrayList(); } selectList.add(exp); } --- 102,119 ---- } ! void addSelectItem(Expression exp, String alias) { if (selectList == null) { selectList = new ArrayList(); + selectColumnNames = new HashMap(); } selectList.add(exp); + Integer offset = new Integer(selectList.size() -1); + if (exp instanceof Column) { + selectColumnNames.put(((Column) exp).name, offset); + } + if (alias != null) { + addAlias(alias, exp); + selectColumnNames.put(alias, offset); + } } *************** *** 157,177 **** } ! Object getCachedAggResult(AggregateFunctionCall func, Tuple tuple) { ! Object key = getAggregateCacheKey(func, tuple); ! return aggregateCache.get(key); ! } ! ! private Object getAggregateCacheKey(AggregateFunctionCall func, Tuple tuple) { ! if (groupByList == null || tuple == null) { ! return func; ! } ! ArrayList al = new ArrayList(1 + groupByList.size()); ! al.add(func); ! for (int i=0; i<groupByList.size(); i++) { ! Expression exp = (Expression) groupByList.get(i); ! Object val = exp.getValue(tuple); ! al.add(val); } ! return al; } --- 171,182 ---- } ! Object getCachedAggResult(AggregateFunctionCall func) { ! if (currentGroupBy == null) { ! return super.getCachedAggResult(func); } ! List key = new ArrayList(); ! key.add(func); ! key.addAll(currentGroupBy); ! return aggregateCache.get(key); } *************** *** 215,220 **** groupByMap.put(al, new ArrayList()); } ! ((ArrayList) groupByMap.get(al)).add(tuple); } } --- 220,260 ---- groupByMap.put(al, new ArrayList()); } ! ((List) groupByMap.get(al)).add(tuple); } + applyHaving(); + } + + private void applyHaving() { + if (having == null) + return; + boolean isScalar = having.isScalar(); + Iterator groups = groupByMap.entrySet().iterator(); + HashMap newGroupByMap = new HashMap(); + while (groups.hasNext()) { + Map.Entry entry = (Map.Entry) groups.next(); + this.currentGroupBy = (List) entry.getKey(); + List tuples = (List) entry.getValue(); + if (isScalar) { + Boolean B = having.getBooleanValue((Tuple) tuples.get(0)); + if (B != null && B.booleanValue()) { + newGroupByMap.put(entry.getKey(), entry.getValue()); + } + } else { + boolean keep = false; + for (int i=0; i<tuples.size(); i++) { + Tuple tup = (Tuple) tuples.get(i); + Boolean B = having.getBooleanValue(tup); + if (B != null && B.booleanValue()) { + keep = true; + break; + } + } + if (keep) { + newGroupByMap.put(entry.getKey(), entry.getValue()); + } + } + this.groupByMap = newGroupByMap; + } + this.currentGroupBy = null; } *************** *** 234,238 **** } calculateAggregates(); ! sortResults(); } } --- 274,365 ---- } calculateAggregates(); ! if (groupByList == null) { ! sortResults(); ! } ! generateRows(); ! if (groupByList != null) { ! sortResults(); ! } ! } ! ! private void generateRows() { ! if (selectList == null || selectList.size() ==0) { ! return; ! } ! if (groupByList != null && groupByList.size() >0) { ! ArrayList groupedRows = new ArrayList(groupByMap.size()); ! for (Iterator it = groupByMap.keySet().iterator(); it.hasNext();) { ! this.currentGroupBy = (List) it.next(); ! this.currentGroupByValues = new HashMap(); ! for (int i=0; i<groupByList.size(); i++) { ! Column c = (Column) groupByList.get(i); ! currentGroupByValues.put(c.name, currentGroupBy.get(i)); ! } ! SelectedRow row = new SelectedRow(); ! for (int i=0; i<selectList.size();i++) { ! Expression exp = (Expression) selectList.get(i); ! row.add(exp.getValue(null)); ! } ! groupedRows.add(row); ! this.currentGroupBy = null; ! this.currentGroupByValues = null; ! } ! this.entities = groupedRows; ! } else { ! if (isScalar()) { ! SelectedRow row = new SelectedRow(); ! for (int i=0; i<selectList.size(); i++) { ! Expression exp = (Expression) selectList.get(i); ! row.add(exp.getValue(null)); ! } ! entities = new ArrayList(); ! entities.add(row); ! } else { ! for (int i=0; i<entities.size(); i++) { ! Tuple row = new SelectedRow((Tuple) entities.get(i)); ! entities.set(i, row); ! } ! if (distinct) { ! entities = removeDuplicates(entities); ! } ! } ! } ! } ! ! ! class SelectedRow extends ArrayList implements Tuple { ! ! SelectedRow() { ! super(Select.this.selectList.size()); ! } ! ! SelectedRow(Tuple tup) { ! this(); ! for (int i=0; i<selectList.size(); i++) { ! Expression exp = (Expression) selectList.get(i); ! add(exp.getValue(tup)); ! } ! } ! ! public Object get(String name) { ! Integer offset = (Integer) selectColumnNames.get(name); ! if (offset == null) { ! throw new InvalidFieldException("No attribute named: " + name); ! } ! return get(offset.intValue()); ! } ! } ! ! static List removeDuplicates(List items) { ! List result = new ArrayList(); ! HashSet set = new HashSet(); ! for (int i=0; i< items.size(); i++) { ! Object item = items.get(i); ! if (!set.contains(item)) { ! set.add(item); ! result.add(item); ! } ! } ! return result; } } Index: Statement.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Statement.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Statement.java 10 Oct 2003 14:47:26 -0000 1.5 --- Statement.java 11 Oct 2003 18:11:10 -0000 1.6 *************** *** 53,61 **** } ! void cacheAggResult(AggregateFunctionCall func, Tuple tuple, Object value) { aggregateCache.put(func, value); } ! Object getCachedAggResult(AggregateFunctionCall func, Tuple tuple) { return aggregateCache.get(func); } --- 53,61 ---- } ! void cacheAggResult(AggregateFunctionCall func, Object value) { aggregateCache.put(func, value); } ! Object getCachedAggResult(AggregateFunctionCall func) { return aggregateCache.get(func); } *************** *** 65,69 **** AggregateFunctionCall afc = (AggregateFunctionCall) aggregateFunctions.get(i); Number aggVal = afc.evaluate(entities); ! cacheAggResult(afc, null, aggVal); } } --- 65,69 ---- AggregateFunctionCall afc = (AggregateFunctionCall) aggregateFunctions.get(i); Number aggVal = afc.evaluate(entities); ! cacheAggResult(afc, aggVal); } } Index: UnaryExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/UnaryExpression.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** UnaryExpression.java 10 Oct 2003 14:47:26 -0000 1.3 --- UnaryExpression.java 11 Oct 2003 18:11:10 -0000 1.4 *************** *** 34,36 **** --- 34,47 ---- return nestedExpression.isScalar(); } + + public boolean equals(Object obj) { + if (obj instanceof UnaryExpression) { + UnaryExpression other = (UnaryExpression) obj; + return other.operator.equals(operator) && nestedExpression.equals(other.nestedExpression); + } + if (obj instanceof Expression) { + return operator.equals("+") && nestedExpression.equals(obj); + } + return false; + } } |
From: <re...@us...> - 2003-10-10 15:53:50
|
Update of /cvsroot/oreo/oreo/src/org/oreodata/sql In directory sc8-pr-cvs1:/tmp/cvs-serv15090 Modified Files: BetweenExpression.java ComparisonExpression.java Expression.java Log Message: bugfixes Index: BetweenExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/BetweenExpression.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BetweenExpression.java 10 Oct 2003 14:47:26 -0000 1.3 --- BetweenExpression.java 10 Oct 2003 15:53:44 -0000 1.4 *************** *** 23,39 **** public Object getValue(Tuple tuple) { ! Comparable val = (Comparable) arg.getValue(tuple); if (val == null) { return null; } ! Comparable leftVal = (Comparable) left.getValue(tuple); if (leftVal != null) { ! if (val.compareTo(leftVal) < 0) { return not ? Boolean.TRUE : Boolean.FALSE; } } ! Comparable rightVal = (Comparable) right.getValue(tuple); if (rightVal != null) { ! if (val.compareTo(rightVal) > 0) { return not ? Boolean.TRUE : Boolean.FALSE; } --- 23,39 ---- public Object getValue(Tuple tuple) { ! Object val = arg.getValue(tuple); if (val == null) { return null; } ! Object leftVal = left.getValue(tuple); if (leftVal != null) { ! if (COMPARATOR.compare(val, leftVal) < 0) { return not ? Boolean.TRUE : Boolean.FALSE; } } ! Object rightVal = right.getValue(tuple); if (rightVal != null) { ! if (COMPARATOR.compare(val, rightVal) > 0) { return not ? Boolean.TRUE : Boolean.FALSE; } Index: ComparisonExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/ComparisonExpression.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ComparisonExpression.java 10 Oct 2003 14:47:26 -0000 1.4 --- ComparisonExpression.java 10 Oct 2003 15:53:44 -0000 1.5 *************** *** 52,58 **** return b ? Boolean.TRUE : Boolean.FALSE; } ! Comparable c1 = (Comparable) val1; ! Comparable c2 = (Comparable) val2; ! int comp = c1.compareTo(c2); boolean cond = false; if (operator == LESS_THAN) { --- 52,56 ---- return b ? Boolean.TRUE : Boolean.FALSE; } ! int comp = COMPARATOR.compare(val1, val2); boolean cond = false; if (operator == LESS_THAN) { Index: Expression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Expression.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Expression.java 10 Oct 2003 14:47:26 -0000 1.4 --- Expression.java 10 Oct 2003 15:53:44 -0000 1.5 *************** *** 2,5 **** --- 2,6 ---- import org.oreodata.Tuple; + import java.util.Comparator; abstract class Expression { *************** *** 36,38 **** --- 37,55 ---- abstract Object getValue(Tuple tuple); + + static final Comparator COMPARATOR = new Comparator() { + public int compare(Object obj1, Object obj2) { + if (obj1.getClass() == obj2.getClass()) { + return ((Comparable) obj1).compareTo((Comparable) obj2); + } + double diff = ((Number) obj1).doubleValue() - ((Number) obj2).doubleValue(); + if (diff < 0d) { + return -1; + } + if (diff > 0d) { + return 1; + } + return 0; + } + }; } |
Update of /cvsroot/oreo/oreo/src/org/oreodata In directory sc8-pr-cvs1:/tmp/cvs-serv3275 Modified Files: AbstractDataSource.java AbstractRecord.java CompactRecord.java DefaultRecord.java Record.java Log Message: further work towards grouping, fixed IN implementation Index: AbstractDataSource.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/AbstractDataSource.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** AbstractDataSource.java 8 Oct 2003 15:52:15 -0000 1.14 --- AbstractDataSource.java 10 Oct 2003 14:47:26 -0000 1.15 *************** *** 345,349 **** List result = select(select, comparator); select.setEntities(result); ! return result; } --- 345,350 ---- List result = select(select, comparator); select.setEntities(result); ! // select.handleGroupBy(); // currently unimplemented ! return select.getEntities(); } Index: AbstractRecord.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/AbstractRecord.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AbstractRecord.java 28 Sep 2003 23:35:48 -0000 1.5 --- AbstractRecord.java 10 Oct 2003 14:47:26 -0000 1.6 *************** *** 457,462 **** abstract void setImmutable(boolean b); ! abstract protected Object get(int i); ! abstract protected void set(int i, Object value); } --- 457,462 ---- abstract void setImmutable(boolean b); ! // abstract protected Object get(int i); ! abstract public void set(int i, Object value); } Index: CompactRecord.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/CompactRecord.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CompactRecord.java 4 Sep 2003 19:20:15 -0000 1.3 --- CompactRecord.java 10 Oct 2003 14:47:26 -0000 1.4 *************** *** 47,51 **** * resulting storage format should be human-readable and * modifiable in a text editor in a pinch. ! * @author <a href="mailto:jo...@re...>Jonathan Revusky</a> */ --- 47,51 ---- * resulting storage format should be human-readable and * modifiable in a text editor in a pinch. ! * @author <a href="mailto:jo...@re...">Jonathan Revusky</a> */ *************** *** 77,81 **** } ! protected final Object get(int i) { Object result = null; if (mutableValues != null) { --- 77,81 ---- } ! public final Object get(int i) { Object result = null; if (mutableValues != null) { *************** *** 92,96 **** } ! protected final void set(int i, Object value) { if (isImmutable()) { throw new ImmutableDataException(); --- 92,96 ---- } ! public final void set(int i, Object value) { if (isImmutable()) { throw new ImmutableDataException(); Index: DefaultRecord.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/DefaultRecord.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** DefaultRecord.java 4 Sep 2003 19:20:15 -0000 1.8 --- DefaultRecord.java 10 Oct 2003 14:47:26 -0000 1.9 *************** *** 68,72 **** } ! protected final void set(int i, Object value) { if (isImmutable()) throw new ImmutableDataException(this); --- 68,72 ---- } ! public final void set(int i, Object value) { if (isImmutable()) throw new ImmutableDataException(this); *************** *** 75,79 **** } ! protected final Object get(int i) { FieldDescriptor field = getMetadata().getField(i); return field.getCopy(values[i]); --- 75,79 ---- } ! public final Object get(int i) { FieldDescriptor field = getMetadata().getField(i); return field.getCopy(values[i]); Index: Record.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/Record.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Record.java 4 Sep 2003 19:20:16 -0000 1.4 --- Record.java 10 Oct 2003 14:47:26 -0000 1.5 *************** *** 80,84 **** */ ! public interface Record { /** * @return the name of this record type --- 80,84 ---- */ ! public interface Record extends Tuple { /** * @return the name of this record type |
Update of /cvsroot/oreo/oreo/src/org/oreodata/sql In directory sc8-pr-cvs1:/tmp/cvs-serv3275/sql Modified Files: AggregateFunction.java AggregateFunctionCall.java AndExpression.java ArithmeticExpression.java BetweenExpression.java Column.java ComparisonExpression.java Expression.java FunctionCall.java InExpression.java NotCondition.java NullComparison.java NumberLiteral.java OrExpression.java OrderByClause.java Parenthesis.java PlaceHolder.java SQLParser.jj Select.java Statement.java StringLiteral.java UnaryExpression.java Log Message: further work towards grouping, fixed IN implementation Index: AggregateFunction.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/AggregateFunction.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AggregateFunction.java 8 Oct 2003 23:54:42 -0000 1.2 --- AggregateFunction.java 10 Oct 2003 14:47:26 -0000 1.3 *************** *** 2,5 **** --- 2,6 ---- import java.util.*; + import org.oreodata.Tuple; public interface AggregateFunction { *************** *** 18,22 **** Number min = null; for (int i=0; i<entities.size(); i++) { ! Number N = exp.getNumericalValue(entities.get(i)); if (N != null) { if (min == null || ((Comparable) min).compareTo(N) >0) { --- 19,23 ---- Number min = null; for (int i=0; i<entities.size(); i++) { ! Number N = exp.getNumericalValue((Tuple) entities.get(i)); if (N != null) { if (min == null || ((Comparable) min).compareTo(N) >0) { *************** *** 33,37 **** Number max = null; for (int i=0; i<entities.size(); i++) { ! Number N = exp.getNumericalValue(entities.get(i)); if (N != null) { if (max == null || ((Comparable) max).compareTo(N) <0) { --- 34,38 ---- Number max = null; for (int i=0; i<entities.size(); i++) { ! Number N = exp.getNumericalValue((Tuple) entities.get(i)); if (N != null) { if (max == null || ((Comparable) max).compareTo(N) <0) { *************** *** 49,54 **** int nonNullItems = 0; for (int i=0; i<entities.size(); i++) { ! Object entity = entities.get(i); ! Number value = exp.getNumericalValue(entity); if (value != null) { sum += value.doubleValue(); --- 50,55 ---- int nonNullItems = 0; for (int i=0; i<entities.size(); i++) { ! Tuple tuple = (Tuple) entities.get(i); ! Number value = exp.getNumericalValue(tuple); if (value != null) { sum += value.doubleValue(); *************** *** 64,69 **** double sum = 0d; for (int i=0; i<entities.size(); i++) { ! Object entity = entities.get(i); ! Number value = exp.getNumericalValue(entity); if (value != null) { sum += value.doubleValue(); --- 65,70 ---- double sum = 0d; for (int i=0; i<entities.size(); i++) { ! Tuple tuple = (Tuple) entities.get(i); ! Number value = exp.getNumericalValue(tuple); if (value != null) { sum += value.doubleValue(); Index: AggregateFunctionCall.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/AggregateFunctionCall.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AggregateFunctionCall.java 9 Oct 2003 22:48:26 -0000 1.4 --- AggregateFunctionCall.java 10 Oct 2003 14:47:26 -0000 1.5 *************** *** 2,12 **** import java.util.*; public class AggregateFunctionCall extends Expression { private String functionName; - private AggregateFunction aggfunc; private Expression arg; private boolean distinct; Number cachedValue; --- 2,13 ---- import java.util.*; + import org.oreodata.Tuple; public class AggregateFunctionCall extends Expression { private String functionName; private Expression arg; private boolean distinct; + AggregateFunction aggfunc; Number cachedValue; *************** *** 40,50 **** } ! Object getValue(Object entity) { ! Object result = stmt.getCachedAggResult(this, entity); ! if (result == null) { ! result = aggfunc.evaluate(arg, stmt.entities); ! stmt.cacheAggResult(this, entity, result); ! } ! return result; } --- 41,51 ---- } ! Object getValue(Tuple tuple) { ! // We are assuming here that all aggregates have already been calculated and cached. ! return stmt.getCachedAggResult(this, tuple); ! } ! ! Number evaluate(List tuples) { ! return aggfunc.evaluate(arg, tuples); } Index: AndExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/AndExpression.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AndExpression.java 9 Oct 2003 22:48:26 -0000 1.2 --- AndExpression.java 10 Oct 2003 14:47:26 -0000 1.3 *************** *** 2,5 **** --- 2,6 ---- import java.util.List; + import org.oreodata.Tuple; class AndExpression extends Expression { *************** *** 17,22 **** } ! public Object getValue(Object entity) { ! Boolean B = left.getBooleanValue(entity); if (B == null) { return null; --- 18,23 ---- } ! public Object getValue(Tuple tuple) { ! Boolean B = left.getBooleanValue(tuple); if (B == null) { return null; *************** *** 25,29 **** return Boolean.FALSE; } ! B = right.getBooleanValue(entity); if (B == null) { return null; --- 26,30 ---- return Boolean.FALSE; } ! B = right.getBooleanValue(tuple); if (B == null) { return null; Index: ArithmeticExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/ArithmeticExpression.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ArithmeticExpression.java 9 Oct 2003 22:48:26 -0000 1.2 --- ArithmeticExpression.java 10 Oct 2003 14:47:26 -0000 1.3 *************** *** 2,5 **** --- 2,6 ---- import java.util.List; + import org.oreodata.Tuple; class ArithmeticExpression extends Expression { *************** *** 28,37 **** } ! public Object getValue(Object entity) { ! Number N1 = left.getNumericalValue(entity); if (N1 == null) { return null; } ! Number N2 = right.getNumericalValue(entity); if (N2 == null) { return null; --- 29,38 ---- } ! public Object getValue(Tuple tuple) { ! Number N1 = left.getNumericalValue(tuple); if (N1 == null) { return null; } ! Number N2 = right.getNumericalValue(tuple); if (N2 == null) { return null; Index: BetweenExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/BetweenExpression.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BetweenExpression.java 9 Oct 2003 22:48:26 -0000 1.2 --- BetweenExpression.java 10 Oct 2003 14:47:26 -0000 1.3 *************** *** 2,5 **** --- 2,6 ---- import java.util.List; + import org.oreodata.Tuple; class BetweenExpression extends Expression { *************** *** 21,30 **** } ! public Object getValue(Object entity) { ! Comparable val = (Comparable) arg.getValue(entity); if (val == null) { return null; } ! Comparable leftVal = (Comparable) left.getValue(entity); if (leftVal != null) { if (val.compareTo(leftVal) < 0) { --- 22,31 ---- } ! public Object getValue(Tuple tuple) { ! Comparable val = (Comparable) arg.getValue(tuple); if (val == null) { return null; } ! Comparable leftVal = (Comparable) left.getValue(tuple); if (leftVal != null) { if (val.compareTo(leftVal) < 0) { *************** *** 32,36 **** } } ! Comparable rightVal = (Comparable) right.getValue(entity); if (rightVal != null) { if (val.compareTo(rightVal) > 0) { --- 33,37 ---- } } ! Comparable rightVal = (Comparable) right.getValue(tuple); if (rightVal != null) { if (val.compareTo(rightVal) > 0) { Index: Column.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Column.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Column.java 9 Oct 2003 22:48:26 -0000 1.3 --- Column.java 10 Oct 2003 14:47:26 -0000 1.4 *************** *** 68,72 **** } ! Object getValue(Object entity) { checkAliases(); String name = this.name; --- 68,72 ---- } ! Object getValue(Tuple tuple) { checkAliases(); String name = this.name; *************** *** 76,91 **** if (aliased != null) { if (aliased instanceof Expression) { ! return ((Expression) aliased).getValue(entity); } name = (String) aliased; } } ! if (entity instanceof Record) { ! return ((Record) entity).get(name); ! } ! if (entity instanceof Map) { ! return ((Map) entity).get(name); ! } ! throw new UnsupportedOperationException("Expecting Record or Map"); } --- 76,85 ---- if (aliased != null) { if (aliased instanceof Expression) { ! return ((Expression) aliased).getValue(tuple); } name = (String) aliased; } } ! return tuple.get(name); } Index: ComparisonExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/ComparisonExpression.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ComparisonExpression.java 9 Oct 2003 22:48:26 -0000 1.3 --- ComparisonExpression.java 10 Oct 2003 14:47:26 -0000 1.4 *************** *** 2,5 **** --- 2,6 ---- import java.util.List; + import org.oreodata.Tuple; import org.oreodata.predicates.SQLQueryUtil; *************** *** 33,42 **** } ! public Object getValue(Object entity) { ! Object val1 = left.getValue(entity); if (val1 == null) { return null; } ! Object val2 = right.getValue(entity); if (val2 == null) return null; --- 34,43 ---- } ! public Object getValue(Tuple tuple) { ! Object val1 = left.getValue(tuple); if (val1 == null) { return null; } ! Object val2 = right.getValue(tuple); if (val2 == null) return null; Index: Expression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Expression.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Expression.java 9 Oct 2003 22:48:26 -0000 1.3 --- Expression.java 10 Oct 2003 14:47:26 -0000 1.4 *************** *** 1,4 **** --- 1,6 ---- package org.oreodata.sql; + import org.oreodata.Tuple; + abstract class Expression { *************** *** 12,21 **** } ! Boolean getBooleanValue(Object entity) { ! return (Boolean) getValue(entity); } ! Number getNumericalValue(Object entity) { ! Object val = getValue(entity); if (val instanceof Number) { return (Number) val; --- 14,23 ---- } ! Boolean getBooleanValue(Tuple tuple) { ! return (Boolean) getValue(tuple); } ! Number getNumericalValue(Tuple tuple) { ! Object val = getValue(tuple); if (val instanceof Number) { return (Number) val; *************** *** 27,36 **** } ! String getStringValue(Object entity) { ! return (String) getValue(entity); } abstract boolean isScalar(); ! abstract Object getValue(Object entity); } --- 29,38 ---- } ! String getStringValue(Tuple tuple) { ! return (String) getValue(tuple); } abstract boolean isScalar(); ! abstract Object getValue(Tuple tuple); } Index: FunctionCall.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/FunctionCall.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FunctionCall.java 9 Oct 2003 22:48:26 -0000 1.5 --- FunctionCall.java 10 Oct 2003 14:47:26 -0000 1.6 *************** *** 2,5 **** --- 2,6 ---- import java.util.*; + import org.oreodata.Tuple; public class FunctionCall extends Expression { *************** *** 32,36 **** } ! Object getValue(Object entity) { List values = new ArrayList(); if (args != null) { --- 33,37 ---- } ! Object getValue(Tuple tuple) { List values = new ArrayList(); if (args != null) { *************** *** 39,43 **** for (int i=0; i<values.size(); i++) { Expression exp = (Expression) args.get(i); ! Object value = exp.getValue(entity); values.set(i, value); } --- 40,44 ---- for (int i=0; i<values.size(); i++) { Expression exp = (Expression) args.get(i); ! Object value = exp.getValue(tuple); values.set(i, value); } Index: InExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/InExpression.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** InExpression.java 9 Oct 2003 22:48:26 -0000 1.2 --- InExpression.java 10 Oct 2003 14:47:26 -0000 1.3 *************** *** 2,5 **** --- 2,6 ---- import java.util.List; + import org.oreodata.Tuple; class InExpression extends Expression { *************** *** 11,14 **** --- 12,16 ---- InExpression(Expression arg, List items, boolean not) { super(arg.stmt); + this.arg = arg; this.items = items; this.not = not; *************** *** 29,34 **** } ! public Object getValue(Object entity) { ! Object val = (Comparable) arg.getValue(entity); if (val == null) { return null; --- 31,36 ---- } ! public Object getValue(Tuple tuple) { ! Object val = (Comparable) arg.getValue(tuple); if (val == null) { return null; *************** *** 37,41 **** for (int i=0; i<items.size(); i++) { Expression exp = (Expression) items.get(i); ! Object item = exp.getValue(entity); if (item == null) { if (item.equals(val)) { --- 39,43 ---- for (int i=0; i<items.size(); i++) { Expression exp = (Expression) items.get(i); ! Object item = exp.getValue(tuple); if (item == null) { if (item.equals(val)) { *************** *** 43,46 **** --- 45,50 ---- } nullFound = true; + } else if (item.equals(val)) { + return not ? Boolean.FALSE : Boolean.TRUE; } } Index: NotCondition.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/NotCondition.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** NotCondition.java 9 Oct 2003 22:48:26 -0000 1.2 --- NotCondition.java 10 Oct 2003 14:47:26 -0000 1.3 *************** *** 2,5 **** --- 2,6 ---- import java.util.List; + import org.oreodata.Tuple; class NotCondition extends Expression { *************** *** 16,21 **** } ! Object getValue(Object entity) { ! Boolean B = getBooleanValue(entity); if (B == null) return null; --- 17,22 ---- } ! Object getValue(Tuple tuple) { ! Boolean B = getBooleanValue(tuple); if (B == null) return null; Index: NullComparison.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/NullComparison.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** NullComparison.java 9 Oct 2003 22:48:26 -0000 1.3 --- NullComparison.java 10 Oct 2003 14:47:26 -0000 1.4 *************** *** 2,5 **** --- 2,6 ---- import java.util.List; + import org.oreodata.Tuple; class NullComparison extends Expression { *************** *** 21,26 **** } ! Object getValue(Object entity) { ! boolean result = exp.getValue(entity) == null; if (not) result = !result; return result ? Boolean.TRUE : Boolean.FALSE; --- 22,27 ---- } ! Object getValue(Tuple tuple) { ! boolean result = exp.getValue(tuple) == null; if (not) result = !result; return result ? Boolean.TRUE : Boolean.FALSE; Index: NumberLiteral.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/NumberLiteral.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** NumberLiteral.java 9 Oct 2003 22:48:26 -0000 1.2 --- NumberLiteral.java 10 Oct 2003 14:47:26 -0000 1.3 *************** *** 1,4 **** --- 1,6 ---- package org.oreodata.sql; + import org.oreodata.Tuple; + class NumberLiteral extends Expression { *************** *** 16,20 **** } ! Object getValue(Object entity) { return value; } --- 18,22 ---- } ! Object getValue(Tuple tuple) { return value; } Index: OrExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/OrExpression.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** OrExpression.java 9 Oct 2003 22:48:26 -0000 1.2 --- OrExpression.java 10 Oct 2003 14:47:26 -0000 1.3 *************** *** 2,5 **** --- 2,6 ---- import java.util.List; + import org.oreodata.Tuple; class OrExpression extends Expression { *************** *** 17,22 **** } ! public Object getValue(Object entity) { ! Boolean B = left.getBooleanValue(entity); if (B == null) { return null; --- 18,23 ---- } ! public Object getValue(Tuple tuple) { ! Boolean B = left.getBooleanValue(tuple); if (B == null) { return null; *************** *** 25,29 **** return Boolean.TRUE; } ! B = right.getBooleanValue(entity); if (B == null) { return null; --- 26,30 ---- return Boolean.TRUE; } ! B = right.getBooleanValue(tuple); if (B == null) { return null; Index: OrderByClause.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/OrderByClause.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OrderByClause.java 5 Oct 2003 12:57:47 -0000 1.1 --- OrderByClause.java 10 Oct 2003 14:47:26 -0000 1.2 *************** *** 41,46 **** public int compare(Object first, Object second) { for (int i=0; i<items.length; i++) { ! Comparable val1 = (Comparable) items[i].getValue(first); ! Comparable val2 = (Comparable) items[i].getValue(second); int result = val1.compareTo(val2); if (result != 0) { --- 41,55 ---- public int compare(Object first, Object second) { for (int i=0; i<items.length; i++) { ! Comparable val1 = (Comparable) items[i].getValue((Tuple) first); ! Comparable val2 = (Comparable) items[i].getValue((Tuple) second); ! if (val1 == null && val2 == null) { ! return -1; ! } ! if (val1 == null) { ! return 1; ! } ! if (val2 == null) { ! return -1; ! } int result = val1.compareTo(val2); if (result != 0) { Index: Parenthesis.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Parenthesis.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Parenthesis.java 9 Oct 2003 22:48:26 -0000 1.2 --- Parenthesis.java 10 Oct 2003 14:47:26 -0000 1.3 *************** *** 2,5 **** --- 2,6 ---- import java.util.List; + import org.oreodata.Tuple; class Parenthesis extends Expression { *************** *** 16,21 **** } ! Object getValue(Object entity) { ! return nestedExpression.getValue(entity); } --- 17,22 ---- } ! Object getValue(Tuple tuple) { ! return nestedExpression.getValue(tuple); } Index: PlaceHolder.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/PlaceHolder.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PlaceHolder.java 9 Oct 2003 22:48:26 -0000 1.2 --- PlaceHolder.java 10 Oct 2003 14:47:26 -0000 1.3 *************** *** 1,4 **** --- 1,6 ---- package org.oreodata.sql; + import org.oreodata.Tuple; + class PlaceHolder extends Expression { *************** *** 14,18 **** } ! Object getValue(Object entity) { throw new UnsupportedOperationException("No value for parameter known."); } --- 16,20 ---- } ! Object getValue(Tuple tuple) { throw new UnsupportedOperationException("No value for parameter known."); } Index: SQLParser.jj =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/SQLParser.jj,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** SQLParser.jj 9 Oct 2003 14:48:25 -0000 1.7 --- SQLParser.jj 10 Oct 2003 14:47:26 -0000 1.8 *************** *** 393,396 **** --- 393,397 ---- [<NOT> {not = true;}] ( + ( <BETWEEN> {arg = left;} left=AdditiveExpression(stmt) *************** *** 400,406 **** return new BetweenExpression(arg, left, right, not); } ! ) ! | ! ( <IN> {inList = new ArrayList();} <OPEN_PAREN> --- 401,407 ---- return new BetweenExpression(arg, left, right, not); } ! ) ! | ! ( <IN> {inList = new ArrayList();} <OPEN_PAREN> *************** *** 414,417 **** --- 415,419 ---- return new InExpression(left, inList, not); } + ) ) ) Index: Select.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Select.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Select.java 9 Oct 2003 22:48:26 -0000 1.5 --- Select.java 10 Oct 2003 14:47:26 -0000 1.6 *************** *** 13,20 **** List selectList; // If this is null, it's just a "select * ...", otherwise a list of expressions ! List groupByList; // This may be null Expression having; OrderByClause orderByClause; // An object representing the ORDER BY clause, may be null. Select(){} --- 13,23 ---- List selectList; // If this is null, it's just a "select * ...", otherwise a list of expressions ! List groupByList; // The expressions in the GROUP BY Clause. This may be null Expression having; OrderByClause orderByClause; // An object representing the ORDER BY clause, may be null. + Map groupByMap; + + Select(){} *************** *** 131,149 **** } ! public RecordComparator asComparator() { ! return orderByClause; ! } ! ! void cacheAggResult(AggregateFunctionCall func, Object entity, Object value) { ! Object key = getAggregateCacheKey(func, entity); ! aggregateCache.put(key, value); } ! Object getCachedAggResult(AggregateFunctionCall func, Object entity) { ! Object key = getAggregateCacheKey(func, entity); ! return aggregateCache.get(key); } ! public void handleOrderBy() { if (orderByClause != null) { Collections.sort(entities, orderByClause); --- 134,155 ---- } ! boolean isScalar() { ! if (selectList == null) { ! return false; ! } ! for (int i=0; i<selectList.size(); i++) { ! Expression exp = (Expression) selectList.get(i); ! if (!exp.isScalar()) { ! return false; ! } ! } ! return true; } ! public RecordComparator asComparator() { ! return orderByClause; } ! void sortResults() { if (orderByClause != null) { Collections.sort(entities, orderByClause); *************** *** 151,156 **** } ! private Object getAggregateCacheKey(AggregateFunctionCall func, Object entity) { ! if (groupByList == null || entity == null) { return func; } --- 157,167 ---- } ! Object getCachedAggResult(AggregateFunctionCall func, Tuple tuple) { ! Object key = getAggregateCacheKey(func, tuple); ! return aggregateCache.get(key); ! } ! ! private Object getAggregateCacheKey(AggregateFunctionCall func, Tuple tuple) { ! if (groupByList == null || tuple == null) { return func; } *************** *** 159,163 **** for (int i=0; i<groupByList.size(); i++) { Expression exp = (Expression) groupByList.get(i); ! Object val = exp.getValue(entity); al.add(val); } --- 170,174 ---- for (int i=0; i<groupByList.size(); i++) { Expression exp = (Expression) groupByList.get(i); ! Object val = exp.getValue(tuple); al.add(val); } *************** *** 165,179 **** } ! boolean isScalar() { ! if (selectList == null) { ! return false; } ! for (int i=0; i<selectList.size(); i++) { ! Expression exp = (Expression) selectList.get(i); ! if (!exp.isScalar()) { ! return false; } } ! return true; } } --- 176,238 ---- } ! void calculateAggregates() { ! if (groupByList == null || groupByList.size() == 0) { ! super.calculateAggregates(); ! } else { ! groupResults(); ! Iterator groupByIterator = groupByMap.entrySet().iterator(); ! while(groupByIterator.hasNext()) { ! Map.Entry entry = (Map.Entry) groupByIterator.next(); ! List groupByKey = (List) entry.getKey(); ! List tuples = (List) entry.getValue(); ! for (int i=0; i<aggregateFunctions.size(); i++) { ! AggregateFunctionCall afc = (AggregateFunctionCall) aggregateFunctions.get(i); ! Number aggVal = afc.evaluate(tuples); ! ArrayList key = new ArrayList(1 + groupByKey.size()); ! key.add(afc); ! key.addAll(groupByKey); ! aggregateCache.put(key, aggVal); ! } ! } } ! } ! ! ! private void groupResults() { ! if (groupByList == null || groupByList.size() ==0) { ! return; ! } ! groupByMap = new HashMap(); ! for (Iterator it = entities.iterator(); it.hasNext();) { ! Tuple tuple = (Tuple) it.next(); ! ArrayList al = new ArrayList(groupByList.size()); ! for (int i=0; i<groupByList.size(); i++) { ! Expression exp = (Expression) groupByList.get(i); ! Object val = exp.getValue(tuple); ! al.add(val); } + if (!groupByMap.containsKey(al)) { + groupByMap.put(al, new ArrayList()); + } + ((ArrayList) groupByMap.get(al)).add(tuple); } ! } ! ! public void passInData(Iterator it) { ! entities = new ArrayList(); ! while (it.hasNext()) { ! Record rec = (Record) it.next(); ! if (referencedTable.equals(rec.getType())) { ! Boolean B = Boolean.TRUE; ! if (where != null) { ! B = where.getBooleanValue(rec); ! } ! if (B != null && B.booleanValue()) { ! entities.add(rec); ! } ! } ! } ! calculateAggregates(); ! sortResults(); } } Index: Statement.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Statement.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Statement.java 9 Oct 2003 14:48:25 -0000 1.4 --- Statement.java 10 Oct 2003 14:47:26 -0000 1.5 *************** *** 53,62 **** } ! void cacheAggResult(AggregateFunctionCall func, Object entity, Object value) { aggregateCache.put(func, value); } ! Object getCachedAggResult(AggregateFunctionCall func, Object entity) { return aggregateCache.get(func); } } --- 53,70 ---- } ! void cacheAggResult(AggregateFunctionCall func, Tuple tuple, Object value) { aggregateCache.put(func, value); } ! Object getCachedAggResult(AggregateFunctionCall func, Tuple tuple) { return aggregateCache.get(func); + } + + void calculateAggregates() { + for (int i=0; i<aggregateFunctions.size(); i++) { + AggregateFunctionCall afc = (AggregateFunctionCall) aggregateFunctions.get(i); + Number aggVal = afc.evaluate(entities); + cacheAggResult(afc, null, aggVal); + } } } Index: StringLiteral.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/StringLiteral.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** StringLiteral.java 9 Oct 2003 22:48:26 -0000 1.2 --- StringLiteral.java 10 Oct 2003 14:47:26 -0000 1.3 *************** *** 2,5 **** --- 2,6 ---- import java.util.StringTokenizer; + import org.oreodata.Tuple; class StringLiteral extends Expression { *************** *** 46,54 **** } ! String getStringValue(Object entity) { return value; } ! Object getValue(Object entity) { return value; } --- 47,55 ---- } ! String getStringValue(Tuple tuple) { return value; } ! Object getValue(Tuple tuple) { return value; } Index: UnaryExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/UnaryExpression.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** UnaryExpression.java 9 Oct 2003 22:48:26 -0000 1.2 --- UnaryExpression.java 10 Oct 2003 14:47:26 -0000 1.3 *************** *** 2,5 **** --- 2,6 ---- import java.util.List; + import org.oreodata.Tuple; class UnaryExpression extends Expression { *************** *** 18,27 **** } ! Object getValue(Object entity) { if (operator.equals("+")) { ! return getNumericalValue(entity); } if (operator.equals("-")) { ! Number N = getNumericalValue(entity); return new Double(N.doubleValue() * -1); } --- 19,28 ---- } ! Object getValue(Tuple tuple) { if (operator.equals("+")) { ! return getNumericalValue(tuple); } if (operator.equals("-")) { ! Number N = getNumericalValue(tuple); return new Double(N.doubleValue() * -1); } |
From: <re...@us...> - 2003-10-10 14:47:36
|
Update of /cvsroot/oreo/oreo/src/org/oreodata/standalone In directory sc8-pr-cvs1:/tmp/cvs-serv3275/standalone Modified Files: InMemoryDataSource.java Log Message: further work towards grouping, fixed IN implementation Index: InMemoryDataSource.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/standalone/InMemoryDataSource.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** InMemoryDataSource.java 28 Sep 2003 23:35:48 -0000 1.9 --- InMemoryDataSource.java 10 Oct 2003 14:47:26 -0000 1.10 *************** *** 38,41 **** --- 38,42 ---- import org.oreodata.*; import org.oreodata.util.*; + import org.oreodata.sql.Select; import org.xml.sax.SAXException; import org.xml.sax.InputSource; *************** *** 378,381 **** --- 379,392 ---- return result; } + + public List select(String query) throws IOException { + if (query == null) { + return select((RecordFilter) null); + } + Select select = new Select(query); + select.passInData(container.values().iterator()); + return select.getEntities(); + } + public synchronized Record get(String type, Object key) throws IOException { |
From: <re...@us...> - 2003-10-10 14:47:32
|
Update of /cvsroot/oreo/oreo/src/org/oreodata/ref In directory sc8-pr-cvs1:/tmp/cvs-serv3275/ref Modified Files: RecordProxy.java Log Message: further work towards grouping, fixed IN implementation Index: RecordProxy.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/ref/RecordProxy.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** RecordProxy.java 28 Sep 2003 02:18:39 -0000 1.4 --- RecordProxy.java 10 Oct 2003 14:47:26 -0000 1.5 *************** *** 123,126 **** --- 123,130 ---- return getUnderlyingRecord().hasChildren(); } + + public Object get(int i) { + return getUnderlyingRecord().get(i); + } public boolean equals(Object o) { |
Update of /cvsroot/oreo/oreo/src/org/oreodata/sql In directory sc8-pr-cvs1:/tmp/cvs-serv10220 Modified Files: AggregateFunctionCall.java AndExpression.java ArithmeticExpression.java BetweenExpression.java Column.java ComparisonExpression.java Expression.java FunctionCall.java InExpression.java NotCondition.java NullComparison.java NumberLiteral.java OrExpression.java Parenthesis.java PlaceHolder.java Select.java StringLiteral.java UnaryExpression.java Log Message: further work towards supporting aggregates and GROUP BY Index: AggregateFunctionCall.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/AggregateFunctionCall.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AggregateFunctionCall.java 9 Oct 2003 14:48:25 -0000 1.3 --- AggregateFunctionCall.java 9 Oct 2003 22:48:26 -0000 1.4 *************** *** 48,50 **** --- 48,54 ---- return result; } + + boolean isScalar() { + return true; + } } Index: AndExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/AndExpression.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AndExpression.java 7 Oct 2003 17:54:27 -0000 1.1 --- AndExpression.java 9 Oct 2003 22:48:26 -0000 1.2 *************** *** 31,33 **** --- 31,37 ---- return B.booleanValue() ? Boolean.TRUE : Boolean.FALSE; } + + boolean isScalar() { + return left.isScalar() && right.isScalar(); + } } Index: ArithmeticExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/ArithmeticExpression.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ArithmeticExpression.java 7 Oct 2003 17:53:42 -0000 1.1 --- ArithmeticExpression.java 9 Oct 2003 22:48:26 -0000 1.2 *************** *** 50,52 **** --- 50,56 ---- return new Double(d); } + + boolean isScalar() { + return left.isScalar() && right.isScalar(); + } } Index: BetweenExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/BetweenExpression.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BetweenExpression.java 9 Oct 2003 14:48:25 -0000 1.1 --- BetweenExpression.java 9 Oct 2003 22:48:26 -0000 1.2 *************** *** 43,45 **** --- 43,49 ---- return not ? Boolean.FALSE : Boolean.TRUE; } + + boolean isScalar() { + return arg.isScalar() && left.isScalar() && right.isScalar(); + } } Index: Column.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Column.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Column.java 5 Oct 2003 18:14:42 -0000 1.2 --- Column.java 9 Oct 2003 22:48:26 -0000 1.3 *************** *** 89,91 **** --- 89,95 ---- throw new UnsupportedOperationException("Expecting Record or Map"); } + + boolean isScalar() { + return false; + } } Index: ComparisonExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/ComparisonExpression.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ComparisonExpression.java 9 Oct 2003 14:48:25 -0000 1.2 --- ComparisonExpression.java 9 Oct 2003 22:48:26 -0000 1.3 *************** *** 66,68 **** --- 66,72 ---- return cond ? Boolean.TRUE : Boolean.FALSE; } + + boolean isScalar() { + return left.isScalar() && right.isScalar(); + } } Index: Expression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Expression.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Expression.java 7 Oct 2003 17:53:42 -0000 1.2 --- Expression.java 9 Oct 2003 22:48:26 -0000 1.3 *************** *** 31,34 **** --- 31,36 ---- } + abstract boolean isScalar(); + abstract Object getValue(Object entity); } Index: FunctionCall.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/FunctionCall.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** FunctionCall.java 8 Oct 2003 15:52:15 -0000 1.4 --- FunctionCall.java 9 Oct 2003 22:48:26 -0000 1.5 *************** *** 44,46 **** --- 44,59 ---- return function.exec(values); } + + boolean isScalar() { + if (args.size() >0) { + for (int i=0; i<args.size(); i++) { + Expression exp = (Expression) args.get(i); + if (!exp.isScalar()) { + return false; + } + } + return true; + } + return false; // REVISIT + } } Index: InExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/InExpression.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** InExpression.java 9 Oct 2003 14:48:25 -0000 1.1 --- InExpression.java 9 Oct 2003 22:48:26 -0000 1.2 *************** *** 50,52 **** --- 50,65 ---- return not ? Boolean.TRUE : Boolean.FALSE; } + + boolean isScalar() { + if (!arg.isScalar()) { + return false; + } + for (int i=0; i<items.size(); i++) { + Expression exp = (Expression) items.get(i); + if (!exp.isScalar()) { + return false; + } + } + return true; + } } Index: NotCondition.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/NotCondition.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NotCondition.java 5 Oct 2003 12:57:47 -0000 1.1 --- NotCondition.java 9 Oct 2003 22:48:26 -0000 1.2 *************** *** 22,24 **** --- 22,28 ---- return B.booleanValue() ? Boolean.FALSE : Boolean.TRUE; } + + boolean isScalar() { + return condition.isScalar(); + } } Index: NullComparison.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/NullComparison.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** NullComparison.java 7 Oct 2003 17:53:42 -0000 1.2 --- NullComparison.java 9 Oct 2003 22:48:26 -0000 1.3 *************** *** 26,28 **** --- 26,32 ---- return result ? Boolean.TRUE : Boolean.FALSE; } + + boolean isScalar() { + return exp.isScalar(); + } } Index: NumberLiteral.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/NumberLiteral.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NumberLiteral.java 5 Oct 2003 12:57:47 -0000 1.1 --- NumberLiteral.java 9 Oct 2003 22:48:26 -0000 1.2 *************** *** 19,21 **** --- 19,25 ---- return value; } + + boolean isScalar() { + return true; + } } Index: OrExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/OrExpression.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OrExpression.java 7 Oct 2003 17:54:27 -0000 1.1 --- OrExpression.java 9 Oct 2003 22:48:26 -0000 1.2 *************** *** 31,33 **** --- 31,37 ---- return B.booleanValue() ? Boolean.TRUE : Boolean.FALSE; } + + boolean isScalar() { + return left.isScalar() && right.isScalar(); + } } Index: Parenthesis.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Parenthesis.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Parenthesis.java 5 Oct 2003 12:57:47 -0000 1.1 --- Parenthesis.java 9 Oct 2003 22:48:26 -0000 1.2 *************** *** 19,21 **** --- 19,25 ---- return nestedExpression.getValue(entity); } + + boolean isScalar() { + return nestedExpression.isScalar(); + } } Index: PlaceHolder.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/PlaceHolder.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PlaceHolder.java 5 Oct 2003 12:57:47 -0000 1.1 --- PlaceHolder.java 9 Oct 2003 22:48:26 -0000 1.2 *************** *** 17,19 **** --- 17,23 ---- throw new UnsupportedOperationException("No value for parameter known."); } + + boolean isScalar() { + return true; + } } Index: Select.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Select.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Select.java 9 Oct 2003 14:48:25 -0000 1.4 --- Select.java 9 Oct 2003 22:48:26 -0000 1.5 *************** *** 164,166 **** --- 164,179 ---- return al; } + + boolean isScalar() { + if (selectList == null) { + return false; + } + for (int i=0; i<selectList.size(); i++) { + Expression exp = (Expression) selectList.get(i); + if (!exp.isScalar()) { + return false; + } + } + return true; + } } Index: StringLiteral.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/StringLiteral.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StringLiteral.java 5 Oct 2003 12:57:47 -0000 1.1 --- StringLiteral.java 9 Oct 2003 22:48:26 -0000 1.2 *************** *** 53,55 **** --- 53,59 ---- return value; } + + boolean isScalar() { + return true; + } } Index: UnaryExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/UnaryExpression.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** UnaryExpression.java 5 Oct 2003 12:57:47 -0000 1.1 --- UnaryExpression.java 9 Oct 2003 22:48:26 -0000 1.2 *************** *** 28,30 **** --- 28,35 ---- throw new UnsupportedOperationException(); } + + + boolean isScalar() { + return nestedExpression.isScalar(); + } } |
Update of /cvsroot/oreo/oreo/src/org/oreodata/sql In directory sc8-pr-cvs1:/tmp/cvs-serv3649 Modified Files: AggregateFunctionCall.java ComparisonExpression.java SQLParser.jj Select.java Statement.java Added Files: BetweenExpression.java InExpression.java Log Message: implementing IN and BETWEEN operators --- NEW FILE: BetweenExpression.java --- package org.oreodata.sql; import java.util.List; class BetweenExpression extends Expression { private Expression arg, left, right; boolean not; BetweenExpression(Expression arg, Expression left, Expression right, boolean not) { super(arg.stmt); this.arg = arg; this.left = left; this.right = right; this.not = not; } public String toString() { String notString = not ? " NOT" : ""; return arg + notString + " BETWEEN " + left + " AND " + right; } public Object getValue(Object entity) { Comparable val = (Comparable) arg.getValue(entity); if (val == null) { return null; } Comparable leftVal = (Comparable) left.getValue(entity); if (leftVal != null) { if (val.compareTo(leftVal) < 0) { return not ? Boolean.TRUE : Boolean.FALSE; } } Comparable rightVal = (Comparable) right.getValue(entity); if (rightVal != null) { if (val.compareTo(rightVal) > 0) { return not ? Boolean.TRUE : Boolean.FALSE; } } if (leftVal == null || rightVal == null) { return null; } return not ? Boolean.FALSE : Boolean.TRUE; } } --- NEW FILE: InExpression.java --- package org.oreodata.sql; import java.util.List; class InExpression extends Expression { private Expression arg; private List items; boolean not; InExpression(Expression arg, List items, boolean not) { super(arg.stmt); this.items = items; this.not = not; } public String toString() { StringBuffer buf = new StringBuffer(); buf.append(arg); if (not) buf.append(" NOT"); buf.append(" IN ("); for (int i=0; i<items.size(); i++) { buf.append(items.get(i)); buf.append(","); } buf.setLength(buf.length() -1); buf.append(")"); return buf.toString(); } public Object getValue(Object entity) { Object val = (Comparable) arg.getValue(entity); if (val == null) { return null; } boolean nullFound = false; for (int i=0; i<items.size(); i++) { Expression exp = (Expression) items.get(i); Object item = exp.getValue(entity); if (item == null) { if (item.equals(val)) { return not ? Boolean.FALSE : Boolean.TRUE; } nullFound = true; } } if (nullFound) { return null; } return not ? Boolean.TRUE : Boolean.FALSE; } } Index: AggregateFunctionCall.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/AggregateFunctionCall.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AggregateFunctionCall.java 8 Oct 2003 23:54:42 -0000 1.2 --- AggregateFunctionCall.java 9 Oct 2003 14:48:25 -0000 1.3 *************** *** 41,48 **** Object getValue(Object entity) { ! if (cachedValue == null) { ! cachedValue = aggfunc.evaluate(arg, stmt.entities); } ! return cachedValue; } } --- 41,50 ---- Object getValue(Object entity) { ! Object result = stmt.getCachedAggResult(this, entity); ! if (result == null) { ! result = aggfunc.evaluate(arg, stmt.entities); ! stmt.cacheAggResult(this, entity, result); } ! return result; } } Index: ComparisonExpression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/ComparisonExpression.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ComparisonExpression.java 7 Oct 2003 17:53:42 -0000 1.1 --- ComparisonExpression.java 9 Oct 2003 14:48:25 -0000 1.2 *************** *** 2,5 **** --- 2,6 ---- import java.util.List; + import org.oreodata.predicates.SQLQueryUtil; class ComparisonExpression extends Expression { *************** *** 14,18 **** LESS_THAN = 3, GREATER_THAN_EQUALS = 4, ! LESS_THAN_EQUALS = 5; static final String[] operators = new String[] {"=", "!=", ">", "<", ">=", "<="}; --- 15,21 ---- LESS_THAN = 3, GREATER_THAN_EQUALS = 4, ! LESS_THAN_EQUALS = 5, ! LIKE = 6, ! NOT_LIKE = 7; static final String[] operators = new String[] {"=", "!=", ">", "<", ">=", "<="}; *************** *** 41,44 **** --- 44,52 ---- boolean b = val1.equals(val2); if (operator == NOT_EQUALS) b = !b; + return b ? Boolean.TRUE : Boolean.FALSE; + } + if (operator == LIKE || operator == NOT_LIKE) { + boolean b = SQLQueryUtil.matchLikeString((String) val1, (String) val2); + if (operator == NOT_LIKE) b = !b; return b ? Boolean.TRUE : Boolean.FALSE; } Index: SQLParser.jj =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/SQLParser.jj,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SQLParser.jj 8 Oct 2003 23:54:42 -0000 1.6 --- SQLParser.jj 9 Oct 2003 14:48:25 -0000 1.7 *************** *** 105,111 **** <CLOSE_PAREN: ")" > | ! <FUNCTION: "upper"> | ! <AGGREGATE_FUNCTION : "sum"> | <EQUALS: "=" > --- 105,111 ---- <CLOSE_PAREN: ")" > | ! <FUNCTION: "upper"|"lower"> | ! <AGGREGATE_FUNCTION : "sum"|"max"|"min"|"count"|"avg"> | <EQUALS: "=" > *************** *** 127,130 **** --- 127,136 ---- <NOT: "not"> | + <BETWEEN : "between"> + | + <LIKE : "like"> + | + <NOT_LIKE : "not" <WS> "like"> + | <STRING_LITERAL: "'" (~["'"])* ( "''" (~["'"])* )* "'" > | *************** *** 352,358 **** Expression Comparison(Statement stmt) : { ! Expression left, right = null; int operator = 0; ! boolean nullComp = false, notNull = false; } { --- 358,365 ---- Expression Comparison(Statement stmt) : { ! Expression left, right = null, arg= null; int operator = 0; ! boolean nullComp = false, not = false; ! List inList = null; } { *************** *** 372,381 **** <NOT_EQUALS> {operator = ComparisonExpression.NOT_EQUALS;} | ( ! <IS> [<NOT> {notNull = true;}] <NULL> { ! return new NullComparison(left, notNull); } ) ) right=AdditiveExpression(stmt) --- 379,419 ---- <NOT_EQUALS> {operator = ComparisonExpression.NOT_EQUALS;} | + <LIKE> {operator = ComparisonExpression.LIKE;} + | + <NOT_LIKE> {operator = ComparisonExpression.NOT_LIKE;} + | ( ! <IS> [<NOT> {not = true;}] <NULL> { ! return new NullComparison(left, not); } ) + | + ( + [<NOT> {not = true;}] + ( + <BETWEEN> {arg = left;} + left=AdditiveExpression(stmt) + <AND> + right=AdditiveExpression(stmt) + { + return new BetweenExpression(arg, left, right, not); + } + ) + | + ( + <IN> {inList = new ArrayList();} + <OPEN_PAREN> + arg=AdditiveExpression(stmt) {inList.add(arg);} + ( + <COMMA> + arg=AdditiveExpression(stmt) {inList.add(arg);} + )* + <CLOSE_PAREN> + { + return new InExpression(left, inList, not); + } + ) + ) ) right=AdditiveExpression(stmt) *************** *** 536,540 **** { String funcName = t.image.toUpperCase(); ! return new AggregateFunctionCall(stmt, funcName, getAggregateFunction(funcName), arg, distinct); } } --- 574,580 ---- { String funcName = t.image.toUpperCase(); ! AggregateFunctionCall afc = new AggregateFunctionCall(stmt, funcName, getAggregateFunction(funcName), arg, distinct); ! stmt.addAggregateFunction(afc); ! return afc; } } Index: Select.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Select.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Select.java 8 Oct 2003 23:54:42 -0000 1.3 --- Select.java 9 Oct 2003 14:48:25 -0000 1.4 *************** *** 1,6 **** package org.oreodata.sql; ! import java.util.List; ! import java.util.ArrayList; import java.io.StringReader; import org.oreodata.*; --- 1,5 ---- package org.oreodata.sql; ! import java.util.*; import java.io.StringReader; import org.oreodata.*; *************** *** 25,32 **** } - public void handleGroupBy() { - //TODO - } - static public void main(String[] args) throws Exception { String input = ""; --- 24,27 ---- *************** *** 58,62 **** buf.setLength(buf.length() -1); // get rid of trailing comma } ! buf.append(" FROM "); buf.append(translateTableName(referencedTable)); alias = (String) aliasReverseLookup.get(referencedTable); --- 53,57 ---- buf.setLength(buf.length() -1); // get rid of trailing comma } ! buf.append("\nFROM "); buf.append(translateTableName(referencedTable)); alias = (String) aliasReverseLookup.get(referencedTable); *************** *** 77,85 **** } if (where != null) { ! buf.append(" WHERE "); buf.append(where); } if (groupByList != null) { ! buf.append(" GROUP BY "); for (int i=0; i<groupByList.size(); i++) { buf.append(groupByList.get(i)); --- 72,80 ---- } if (where != null) { ! buf.append("\nWHERE "); buf.append(where); } if (groupByList != null) { ! buf.append("\nGROUP BY "); for (int i=0; i<groupByList.size(); i++) { buf.append(groupByList.get(i)); *************** *** 93,96 **** --- 88,92 ---- } if (orderByClause != null) { + buf.append("\n"); buf.append(orderByClause); } *************** *** 137,140 **** --- 133,166 ---- public RecordComparator asComparator() { return orderByClause; + } + + void cacheAggResult(AggregateFunctionCall func, Object entity, Object value) { + Object key = getAggregateCacheKey(func, entity); + aggregateCache.put(key, value); + } + + Object getCachedAggResult(AggregateFunctionCall func, Object entity) { + Object key = getAggregateCacheKey(func, entity); + return aggregateCache.get(key); + } + + public void handleOrderBy() { + if (orderByClause != null) { + Collections.sort(entities, orderByClause); + } + } + + private Object getAggregateCacheKey(AggregateFunctionCall func, Object entity) { + if (groupByList == null || entity == null) { + return func; + } + ArrayList al = new ArrayList(1 + groupByList.size()); + al.add(func); + for (int i=0; i<groupByList.size(); i++) { + Expression exp = (Expression) groupByList.get(i); + Object val = exp.getValue(entity); + al.add(val); + } + return al; } } Index: Statement.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Statement.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Statement.java 8 Oct 2003 15:52:15 -0000 1.3 --- Statement.java 9 Oct 2003 14:48:25 -0000 1.4 *************** *** 1,6 **** package org.oreodata.sql; ! import java.util.HashMap; ! import java.util.List; import org.oreodata.*; --- 1,5 ---- package org.oreodata.sql; ! import java.util.*; import org.oreodata.*; *************** *** 15,18 **** --- 14,19 ---- Expression where; // the condition for inclusion, may be null. List entities; // the entities satisfying the where clause. + List aggregateFunctions = new ArrayList(); + HashMap aggregateCache = new HashMap(); void addAlias(String alias, Object obj) { *************** *** 21,24 **** --- 22,29 ---- } + void addAggregateFunction(AggregateFunctionCall afc) { + aggregateFunctions.add(afc); + } + String translateTableName(String recordName) { if (recordName == null) return null; *************** *** 38,41 **** --- 43,62 ---- public void setEntities(List entities) { this.entities = entities; + for (int i=0; i<aggregateFunctions.size(); i++) { + AggregateFunctionCall afc = (AggregateFunctionCall) aggregateFunctions.get(i); + Object val = afc.getValue(null); + } + } + + public List getEntities() { + return entities; + } + + void cacheAggResult(AggregateFunctionCall func, Object entity, Object value) { + aggregateCache.put(func, value); + } + + Object getCachedAggResult(AggregateFunctionCall func, Object entity) { + return aggregateCache.get(func); } } |
From: <re...@us...> - 2003-10-08 23:54:48
|
Update of /cvsroot/oreo/oreo/src/org/oreodata/sql In directory sc8-pr-cvs1:/tmp/cvs-serv26860 Modified Files: AggregateFunction.java AggregateFunctionCall.java SQLParser.jj Select.java Log Message: further work towards GROUP BY clause Index: AggregateFunction.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/AggregateFunction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AggregateFunction.java 8 Oct 2003 15:52:15 -0000 1.1 --- AggregateFunction.java 8 Oct 2003 23:54:42 -0000 1.2 *************** *** 5,13 **** public interface AggregateFunction { ! Object evaluate(Expression exp, List items); static AggregateFunction COUNT = new AggregateFunction() { ! public Object evaluate(Expression exp, List entities) { return new Integer(entities.size()); } --- 5,13 ---- public interface AggregateFunction { ! Number evaluate(Expression exp, List items); static AggregateFunction COUNT = new AggregateFunction() { ! public Number evaluate(Expression exp, List entities) { return new Integer(entities.size()); } *************** *** 15,19 **** static AggregateFunction MIN = new AggregateFunction() { ! public Object evaluate(Expression exp, List entities) { Number min = null; for (int i=0; i<entities.size(); i++) { --- 15,19 ---- static AggregateFunction MIN = new AggregateFunction() { ! public Number evaluate(Expression exp, List entities) { Number min = null; for (int i=0; i<entities.size(); i++) { *************** *** 30,34 **** static AggregateFunction MAX = new AggregateFunction() { ! public Object evaluate(Expression exp, List entities) { Number max = null; for (int i=0; i<entities.size(); i++) { --- 30,34 ---- static AggregateFunction MAX = new AggregateFunction() { ! public Number evaluate(Expression exp, List entities) { Number max = null; for (int i=0; i<entities.size(); i++) { *************** *** 45,49 **** static AggregateFunction AVG = new AggregateFunction() { ! public Object evaluate(Expression exp, List entities) { double sum = 0d; int nonNullItems = 0; --- 45,49 ---- static AggregateFunction AVG = new AggregateFunction() { ! public Number evaluate(Expression exp, List entities) { double sum = 0d; int nonNullItems = 0; *************** *** 61,65 **** static AggregateFunction SUM = new AggregateFunction() { ! public Object evaluate(Expression exp, List entities) { double sum = 0d; for (int i=0; i<entities.size(); i++) { --- 61,65 ---- static AggregateFunction SUM = new AggregateFunction() { ! public Number evaluate(Expression exp, List entities) { double sum = 0d; for (int i=0; i<entities.size(); i++) { Index: AggregateFunctionCall.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/AggregateFunctionCall.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AggregateFunctionCall.java 8 Oct 2003 15:52:15 -0000 1.1 --- AggregateFunctionCall.java 8 Oct 2003 23:54:42 -0000 1.2 *************** *** 9,12 **** --- 9,13 ---- private Expression arg; private boolean distinct; + Number cachedValue; AggregateFunctionCall(Statement stmt, *************** *** 40,44 **** Object getValue(Object entity) { ! return aggfunc.evaluate(arg, stmt.entities); } } --- 41,48 ---- Object getValue(Object entity) { ! if (cachedValue == null) { ! cachedValue = aggfunc.evaluate(arg, stmt.entities); ! } ! return cachedValue; } } Index: SQLParser.jj =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/SQLParser.jj,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SQLParser.jj 8 Oct 2003 15:52:15 -0000 1.5 --- SQLParser.jj 8 Oct 2003 23:54:42 -0000 1.6 *************** *** 141,144 **** --- 141,148 ---- <ORDER_BY: "order" <WS> "by" > | + <GROUP_BY: "group" <WS> "by" > + | + <HAVING: "having"> + | <SELECT: "select"> | *************** *** 204,207 **** --- 208,220 ---- ] [ + <GROUP_BY> {select.groupByList = new ArrayList();} + exp=Expression(select) {select.groupByList.add(exp);} + ( + <COMMA> + exp=Expression(select) {select.groupByList.add(exp);} + )* + [<HAVING> select.having = Expression(select)] + ] + [ select.orderByClause=OrderByClause(select) ] *************** *** 505,509 **** } { ! t=<AGGREGATE_FUNCTION> <OPEN_PAREN> ( --- 518,527 ---- } { ! t=<AGGREGATE_FUNCTION> ! { ! if (inWhereClause) ! throw new ParseException("Cannot use aggregate function " + ! t.image + " in WHERE clause"); ! } <OPEN_PAREN> ( Index: Select.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Select.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Select.java 5 Oct 2003 18:14:42 -0000 1.2 --- Select.java 8 Oct 2003 23:54:42 -0000 1.3 *************** *** 8,16 **** /** * A class that represents a compiled SQL select statement. */ public class Select extends Statement implements RecordFilter { ! List selectList; // If this is null, it's just a "select *...", otherwise a list of expressions OrderByClause orderByClause; // An object representing the ORDER BY clause, may be null. --- 8,19 ---- /** * A class that represents a compiled SQL select statement. + * As currently designed, this object is meant to be a throw-away (REVISIT) */ public class Select extends Statement implements RecordFilter { ! List selectList; // If this is null, it's just a "select * ...", otherwise a list of expressions ! List groupByList; // This may be null ! Expression having; OrderByClause orderByClause; // An object representing the ORDER BY clause, may be null. *************** *** 22,25 **** --- 25,32 ---- } + public void handleGroupBy() { + //TODO + } + static public void main(String[] args) throws Exception { String input = ""; *************** *** 72,75 **** --- 79,94 ---- buf.append(" WHERE "); buf.append(where); + } + if (groupByList != null) { + buf.append(" GROUP BY "); + for (int i=0; i<groupByList.size(); i++) { + buf.append(groupByList.get(i)); + buf.append(","); + } + buf.setLength(buf.length() -1); + if (having != null) { + buf.append(" HAVING "); + buf.append(having); + } } if (orderByClause != null) { |
Update of /cvsroot/oreo/oreo/src/org/oreodata/sql In directory sc8-pr-cvs1:/tmp/cvs-serv18423/sql Modified Files: FunctionCall.java SQLParser.jj Statement.java Added Files: AggregateFunction.java AggregateFunctionCall.java Removed Files: CountAll.java Log Message: introducing support for aggregate functions --- NEW FILE: AggregateFunction.java --- package org.oreodata.sql; import java.util.*; public interface AggregateFunction { Object evaluate(Expression exp, List items); static AggregateFunction COUNT = new AggregateFunction() { public Object evaluate(Expression exp, List entities) { return new Integer(entities.size()); } }; static AggregateFunction MIN = new AggregateFunction() { public Object evaluate(Expression exp, List entities) { Number min = null; for (int i=0; i<entities.size(); i++) { Number N = exp.getNumericalValue(entities.get(i)); if (N != null) { if (min == null || ((Comparable) min).compareTo(N) >0) { min = N; } } } return min; } }; static AggregateFunction MAX = new AggregateFunction() { public Object evaluate(Expression exp, List entities) { Number max = null; for (int i=0; i<entities.size(); i++) { Number N = exp.getNumericalValue(entities.get(i)); if (N != null) { if (max == null || ((Comparable) max).compareTo(N) <0) { max = N; } } } return max; } }; static AggregateFunction AVG = new AggregateFunction() { public Object evaluate(Expression exp, List entities) { double sum = 0d; int nonNullItems = 0; for (int i=0; i<entities.size(); i++) { Object entity = entities.get(i); Number value = exp.getNumericalValue(entity); if (value != null) { sum += value.doubleValue(); nonNullItems++; } } return nonNullItems > 0 ? new Double(sum/nonNullItems) : null; } }; static AggregateFunction SUM = new AggregateFunction() { public Object evaluate(Expression exp, List entities) { double sum = 0d; for (int i=0; i<entities.size(); i++) { Object entity = entities.get(i); Number value = exp.getNumericalValue(entity); if (value != null) { sum += value.doubleValue(); } } return new Double(sum); } }; } --- NEW FILE: AggregateFunctionCall.java --- package org.oreodata.sql; import java.util.*; public class AggregateFunctionCall extends Expression { private String functionName; private AggregateFunction aggfunc; private Expression arg; private boolean distinct; AggregateFunctionCall(Statement stmt, String functionName, AggregateFunction aggfunc, Expression arg, boolean distinct) { super(stmt); this.functionName = functionName.toUpperCase(); this.aggfunc = aggfunc; this.arg = arg; this.distinct = distinct; } public String toString() { StringBuffer buf = new StringBuffer(); buf.append(functionName); buf.append("("); if (distinct) { buf.append("DISTINCT "); } if (arg == null) { buf.append("*"); } else { buf.append(arg); } buf.append(")"); return buf.toString(); } Object getValue(Object entity) { return aggfunc.evaluate(arg, stmt.entities); } } Index: FunctionCall.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/FunctionCall.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FunctionCall.java 6 Oct 2003 15:39:29 -0000 1.3 --- FunctionCall.java 8 Oct 2003 15:52:15 -0000 1.4 *************** *** 6,14 **** private String functionName; private List args; ! FunctionCall(Statement stmt, String functionName, List args) { super(stmt); ! this.functionName = functionName.toUpperCase(); this.args = args; } --- 6,16 ---- private String functionName; + private Function function; private List args; ! FunctionCall(Statement stmt, String functionName, Function function, List args) { super(stmt); ! this.functionName = functionName; ! this.function = function; this.args = args; } *************** *** 31,37 **** Object getValue(Object entity) { - Function func = SQLParser.getFunction(functionName); - if (func == null) - throw new UnsupportedOperationException("function " + functionName + " not supported"); List values = new ArrayList(); if (args != null) { --- 33,36 ---- *************** *** 43,47 **** values.set(i, value); } ! return func.exec(values); } } --- 42,46 ---- values.set(i, value); } ! return function.exec(values); } } Index: SQLParser.jj =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/SQLParser.jj,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SQLParser.jj 7 Oct 2003 17:53:42 -0000 1.4 --- SQLParser.jj 8 Oct 2003 15:52:15 -0000 1.5 *************** *** 17,20 **** --- 17,21 ---- static private HashMap functions = new HashMap(); + static private HashMap aggregateFunctions = new HashMap(); static { *************** *** 28,31 **** --- 29,37 ---- registerFunction("RTRIM", Function.RTRIM); registerFunction("CONCAT", Function.CONCAT); + registerAggregateFunction("COUNT", AggregateFunction.COUNT); + registerAggregateFunction("MIN", AggregateFunction.MIN); + registerAggregateFunction("MAX", AggregateFunction.MAX); + registerAggregateFunction("SUM", AggregateFunction.SUM); + registerAggregateFunction("AVG", AggregateFunction.AVG); } *************** *** 34,43 **** --- 40,58 ---- } + static public void registerAggregateFunction(String funcName, AggregateFunction aggFunc) { + aggregateFunctions.put(funcName, aggFunc); + } + static public Function getFunction(String funcName) { return (Function) functions.get(funcName.toUpperCase()); } + + static public AggregateFunction getAggregateFunction(String funcName) { + return (AggregateFunction) aggregateFunctions.get(funcName.toUpperCase()); + } int position; + boolean inWhereClause; } *************** *** 92,96 **** <FUNCTION: "upper"> | ! <COUNT_ALL : "COUNT" (<WS>)? "(" (<WS>)? "*" (<WS>)? ")"> | <EQUALS: "=" > --- 107,111 ---- <FUNCTION: "upper"> | ! <AGGREGATE_FUNCTION : "sum"> | <EQUALS: "=" > *************** *** 122,125 **** --- 137,142 ---- <NULL: "null"> | + <DISTINCT: "distinct"> + | <ORDER_BY: "order" <WS> "by" > | *************** *** 134,141 **** <ASC: "asc"> | - <IDENTIFIER: (<LETTER>)+ (<DIGIT>|<LETTER>|"$"|"_")*> - {if (SQLParser.getFunction(matchedToken.image) != null) matchedToken.kind = FUNCTION;} - | <PLACE_HOLDER: "?"> } --- 151,164 ---- <ASC: "asc"> | <PLACE_HOLDER: "?"> + | + <IDENTIFIER: (<LETTER>)+ (<DIGIT>|<LETTER>|"$"|"_")*> + { + if (SQLParser.getFunction(matchedToken.image) != null) { + matchedToken.kind = FUNCTION; + } else if (SQLParser.getAggregateFunction(matchedToken.image) != null) { + matchedToken.kind = AGGREGATE_FUNCTION; + } + } } *************** *** 176,181 **** )* [ ! <WHERE> ! select.where=Expression(select) ] [ --- 199,205 ---- )* [ ! <WHERE> {inWhereClause = true;} ! select.where=Expression(select) ! {inWhereClause = false;} ] [ *************** *** 433,436 **** --- 457,462 ---- exp=FunctionCall(stmt) | + exp=AggregateFunctionCall(stmt) + | exp=Parenthesis(stmt) | *************** *** 449,458 **** } - CountAll CountAll(Statement stmt) : - {} - { - <COUNT_ALL> {return new CountAll(stmt);} - } - FunctionCall FunctionCall(Statement stmt) : { --- 475,478 ---- *************** *** 473,479 **** <CLOSE_PAREN> { ! StringTokenizer st = new StringTokenizer(t.image, "\n\t\r ("); ! String functionName = st.nextToken(); ! return new FunctionCall(stmt, functionName, args); } } --- 493,522 ---- <CLOSE_PAREN> { ! String functionName = t.image.toUpperCase(); ! return new FunctionCall(stmt, functionName, getFunction(functionName), args); ! } ! } ! ! AggregateFunctionCall AggregateFunctionCall(Statement stmt) : ! { ! Token t; ! Expression arg = null; ! boolean distinct = false; ! } ! { ! t=<AGGREGATE_FUNCTION> ! <OPEN_PAREN> ! ( ! <STAR> ! | ! ( ! [<DISTINCT> {distinct = true;}] ! arg=Expression(stmt) ! ) ! ) ! <CLOSE_PAREN> ! { ! String funcName = t.image.toUpperCase(); ! return new AggregateFunctionCall(stmt, funcName, getAggregateFunction(funcName), arg, distinct); } } Index: Statement.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Statement.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Statement.java 5 Oct 2003 18:14:42 -0000 1.2 --- Statement.java 8 Oct 2003 15:52:15 -0000 1.3 *************** *** 14,17 **** --- 14,18 ---- List supplementalTables; Expression where; // the condition for inclusion, may be null. + List entities; // the entities satisfying the where clause. void addAlias(String alias, Object obj) { *************** *** 33,36 **** --- 34,41 ---- } return recordName; + } + + public void setEntities(List entities) { + this.entities = entities; } } --- CountAll.java DELETED --- |
From: <re...@us...> - 2003-10-08 15:52:25
|
Update of /cvsroot/oreo/oreo/src/org/oreodata In directory sc8-pr-cvs1:/tmp/cvs-serv18423 Modified Files: AbstractDataSource.java Log Message: introducing support for aggregate functions Index: AbstractDataSource.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/AbstractDataSource.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** AbstractDataSource.java 6 Oct 2003 15:39:29 -0000 1.13 --- AbstractDataSource.java 8 Oct 2003 15:52:15 -0000 1.14 *************** *** 343,347 **** Select select = new Select(query); RecordComparator comparator = select.asComparator(); ! return select(select, comparator); } --- 343,349 ---- Select select = new Select(query); RecordComparator comparator = select.asComparator(); ! List result = select(select, comparator); ! select.setEntities(result); ! return result; } |
From: <re...@us...> - 2003-10-07 17:54:32
|
Update of /cvsroot/oreo/oreo/src/org/oreodata/sql In directory sc8-pr-cvs1:/tmp/cvs-serv29901 Added Files: AndExpression.java OrExpression.java Log Message: improvements to SQL grammar --- NEW FILE: AndExpression.java --- package org.oreodata.sql; import java.util.List; class AndExpression extends Expression { private Expression left, right; AndExpression(Expression left, Expression right) { super(left.stmt); this.left = left; this.right = right; } public String toString() { return left + " AND " + right; } public Object getValue(Object entity) { Boolean B = left.getBooleanValue(entity); if (B == null) { return null; } if (!B.booleanValue()) { return Boolean.FALSE; } B = right.getBooleanValue(entity); if (B == null) { return null; } return B.booleanValue() ? Boolean.TRUE : Boolean.FALSE; } } --- NEW FILE: OrExpression.java --- package org.oreodata.sql; import java.util.List; class OrExpression extends Expression { private Expression left, right; OrExpression(Expression left, Expression right) { super(left.stmt); this.left = left; this.right = right; } public String toString() { return left + " OR " + right; } public Object getValue(Object entity) { Boolean B = left.getBooleanValue(entity); if (B == null) { return null; } if (B.booleanValue()) { return Boolean.TRUE; } B = right.getBooleanValue(entity); if (B == null) { return null; } return B.booleanValue() ? Boolean.TRUE : Boolean.FALSE; } } |
Update of /cvsroot/oreo/oreo/src/org/oreodata/sql In directory sc8-pr-cvs1:/tmp/cvs-serv29705 Modified Files: Expression.java NullComparison.java SQLParser.jj Added Files: ArithmeticExpression.java ComparisonExpression.java Removed Files: BinaryExpression.java Log Message: improvements to SQL grammar --- NEW FILE: ArithmeticExpression.java --- package org.oreodata.sql; import java.util.List; class ArithmeticExpression extends Expression { private Expression left, right; private int operator; static final String[] operators = new String[] {"+", "-", "*", "/", "%"}; static final int PLUS = 0, MINUS = 1, TIMES = 2, DIV = 3, MOD = 4; ArithmeticExpression(Expression left, Expression right, int op) { super(left.stmt); this.left = left; this.right = right; this.operator = operator; } public String toString() { return left + " " + operators[operator] + " " + right; } public Object getValue(Object entity) { Number N1 = left.getNumericalValue(entity); if (N1 == null) { return null; } Number N2 = right.getNumericalValue(entity); if (N2 == null) { return null; } double d1 = N1.doubleValue(), d2 = N2.doubleValue(); double d = d1 + d2; if (operator == MINUS) { d = d1 - d2; } else if (operator == TIMES) { d = d1*d2; } else if (operator == DIV) { d = d1/d2; } else if (operator == MOD) { return new Integer(N1.intValue()%N2.intValue()); } return new Double(d); } } --- NEW FILE: ComparisonExpression.java --- package org.oreodata.sql; import java.util.List; class ComparisonExpression extends Expression { private Expression left, right; private int operator; static final int EQUALS = 0, NOT_EQUALS = 1, GREATER_THAN = 2, LESS_THAN = 3, GREATER_THAN_EQUALS = 4, LESS_THAN_EQUALS = 5; static final String[] operators = new String[] {"=", "!=", ">", "<", ">=", "<="}; ComparisonExpression(Expression left, Expression right, int operator) { super(left.stmt); this.left = left; this.right = right; this.operator = operator; } public String toString() { return left + " " + operators[operator] + " " + right; } public Object getValue(Object entity) { Object val1 = left.getValue(entity); if (val1 == null) { return null; } Object val2 = right.getValue(entity); if (val2 == null) return null; if (operator == EQUALS || operator == NOT_EQUALS) { boolean b = val1.equals(val2); if (operator == NOT_EQUALS) b = !b; return b ? Boolean.TRUE : Boolean.FALSE; } Comparable c1 = (Comparable) val1; Comparable c2 = (Comparable) val2; int comp = c1.compareTo(c2); boolean cond = false; if (operator == LESS_THAN) { cond = comp < 0 ; } else if (operator == LESS_THAN_EQUALS) { cond = comp<=0; } else if (operator == GREATER_THAN) { cond = comp >0; } else if (operator == GREATER_THAN_EQUALS) { cond = comp>=0; } return cond ? Boolean.TRUE : Boolean.FALSE; } } Index: Expression.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/Expression.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Expression.java 5 Oct 2003 12:57:47 -0000 1.1 --- Expression.java 7 Oct 2003 17:53:42 -0000 1.2 *************** *** 3,6 **** --- 3,9 ---- abstract class Expression { + static final Integer ONE = new Integer(1); + static final Integer ZERO = new Integer(0); + Statement stmt; *************** *** 14,18 **** Number getNumericalValue(Object entity) { ! return (Number) getValue(entity); } --- 17,28 ---- Number getNumericalValue(Object entity) { ! Object val = getValue(entity); ! if (val instanceof Number) { ! return (Number) val; ! } ! if (val instanceof Boolean) { ! return ((Boolean) val).booleanValue() ? ONE : ZERO; ! } ! throw new ClassCastException("This is not a numerical value."); } Index: NullComparison.java =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/NullComparison.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullComparison.java 5 Oct 2003 12:57:47 -0000 1.1 --- NullComparison.java 7 Oct 2003 17:53:42 -0000 1.2 *************** *** 5,14 **** class NullComparison extends Expression { ! private Column column; boolean not; ! NullComparison(Column column, boolean not) { ! super(column.stmt); ! this.column = column; this.not = not; } --- 5,14 ---- class NullComparison extends Expression { ! private Expression exp; boolean not; ! NullComparison(Expression exp, boolean not) { ! super(exp.stmt); ! this.exp = exp; this.not = not; } *************** *** 16,26 **** public String toString() { if (not) { ! return column + " IS NOT NULL"; } ! return column + " IS NULL"; } Object getValue(Object entity) { ! boolean result = column.getValue(entity) == null; if (not) result = !result; return result ? Boolean.TRUE : Boolean.FALSE; --- 16,26 ---- public String toString() { if (not) { ! return exp + " IS NOT NULL"; } ! return exp + " IS NULL"; } Object getValue(Object entity) { ! boolean result = exp.getValue(entity) == null; if (not) result = !result; return result ? Boolean.TRUE : Boolean.FALSE; Index: SQLParser.jj =================================================================== RCS file: /cvsroot/oreo/oreo/src/org/oreodata/sql/SQLParser.jj,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SQLParser.jj 6 Oct 2003 15:39:29 -0000 1.3 --- SQLParser.jj 7 Oct 2003 17:53:42 -0000 1.4 *************** *** 39,65 **** ! int position; ! ! public static void main(String args[]) throws ParseException { ! String input = ""; ! for (int i=0; i<args.length; i++) { ! input += " "; ! input += args[i]; ! } ! SQLParser parser = new SQLParser(new StringReader(input)); ! Select select = new Select(); ! parser.BuildSelect(select); ! System.out.println(select); ! long t = System.currentTimeMillis(); ! for (int i=0; i<1000; i++) { ! parser = new SQLParser(new StringReader(input)); ! select = new Select(); ! parser.BuildSelect(select); ! String s = select.toString(); ! } ! System.out.println(System.currentTimeMillis() - t); ! System.exit(0); ! } ! } --- 39,43 ---- ! int position; } *************** *** 106,109 **** --- 84,89 ---- <SLASH: "/"> | + <PERCENT: "%"> + | <OPEN_PAREN: "(" > | *************** *** 136,142 **** <AS: "as"> | ! <IS_NULL: "is" <WS> "null"> | ! <IS_NOT_NULL: "is" <WS> "not" <WS> "null"> | <ORDER_BY: "order" <WS> "by" > --- 116,124 ---- <AS: "as"> | ! <IS: "is"> | ! <IN: "in"> ! | ! <NULL: "null"> | <ORDER_BY: "order" <WS> "by" > *************** *** 288,292 **** right=AndExpression(stmt) { ! left = new BinaryExpression(left, right, or.image); } )* --- 270,274 ---- right=AndExpression(stmt) { ! left = new OrExpression(left, right); } )* *************** *** 307,311 **** right=NotCondition(stmt) { ! left = new BinaryExpression(left, right, and.image); } )* --- 289,293 ---- right=NotCondition(stmt) { ! left = new AndExpression(left, right); } )* *************** *** 322,326 **** { [<NOT>{not = true;}] ! exp=Condition(stmt) { if (not) { --- 304,308 ---- { [<NOT>{not = true;}] ! exp=Comparison(stmt) { if (not) { *************** *** 331,354 **** } - Expression Condition(Statement stmt) : - { - Expression exp; - } - { - ( - LOOKAHEAD(2) - exp=NullComparison(stmt) - | - exp=Comparison(stmt) - ) - { - return exp; - } - } - Expression Comparison(Statement stmt) : { Expression left, right = null; ! Token op = null; } { --- 313,321 ---- } Expression Comparison(Statement stmt) : { Expression left, right = null; ! int operator = 0; ! boolean nullComp = false, notNull = false; } { *************** *** 356,370 **** [ ( ! op=<LESS_THAN> | ! op=<LESS_THAN_EQUALS> | ! op=<GREATER_THAN> | ! op=<GREATER_THAN_EQUALS> | ! op=<EQUALS> | ! op=<NOT_EQUALS> ) right=AdditiveExpression(stmt) --- 323,344 ---- [ ( ! <LESS_THAN> {operator = ComparisonExpression.LESS_THAN;} | ! <LESS_THAN_EQUALS> {operator = ComparisonExpression.LESS_THAN_EQUALS;} | ! <GREATER_THAN> {operator = ComparisonExpression.GREATER_THAN;} | ! <GREATER_THAN_EQUALS> {operator = ComparisonExpression.GREATER_THAN_EQUALS;} | ! <EQUALS> {operator = ComparisonExpression.EQUALS;} | ! <NOT_EQUALS> {operator = ComparisonExpression.NOT_EQUALS;} ! | ! ( ! <IS> [<NOT> {notNull = true;}] <NULL> ! { ! return new NullComparison(left, notNull); ! } ! ) ) right=AdditiveExpression(stmt) *************** *** 374,395 **** return left; } ! return new BinaryExpression(left, right, op.image); ! } ! } ! ! Expression NullComparison(Statement stmt) : ! { ! Column column; ! boolean not = false; ! } ! { ! column=Column(stmt) ! ( ! <IS_NULL> ! | ! <IS_NOT_NULL>{not = true;} ! ) ! { ! return new NullComparison(column, not); } } --- 348,352 ---- return left; } ! return new ComparisonExpression(left, right, operator); } } *************** *** 399,403 **** { Expression left, right = null; ! Token op = null; } { --- 356,360 ---- { Expression left, right = null; ! int op = ArithmeticExpression.PLUS; } { *************** *** 405,412 **** ( LOOKAHEAD(<PLUS>|<MINUS>) ! (op=<PLUS>|op=<MINUS>) right=MultiplicativeExpression(stmt) { ! left = new BinaryExpression(left, right, op.image); } )* --- 362,373 ---- ( LOOKAHEAD(<PLUS>|<MINUS>) ! ( ! <PLUS> ! | ! <MINUS>{op=ArithmeticExpression.MINUS;} ! ) right=MultiplicativeExpression(stmt) { ! left = new ArithmeticExpression(left, right, op); } )* *************** *** 420,432 **** { Expression left, right = null; ! Token op = null; } { left=UnaryExpression(stmt) ( ! (op=<STAR>|op=<SLASH>) right=UnaryExpression(stmt) { ! left = new BinaryExpression(left, right, op.image); } )* --- 381,397 ---- { Expression left, right = null; ! int operator = ArithmeticExpression.TIMES; } { left=UnaryExpression(stmt) ( ! ( ! <STAR> ! | ! <SLASH> {operator = ArithmeticExpression.DIV;} ! ) right=UnaryExpression(stmt) { ! left = new ArithmeticExpression(left, right, operator); } )* --- BinaryExpression.java DELETED --- |