Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 3961 invoked from network); 18 Apr 2010 15:06:16 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 18 Apr 2010 15:06:16 -0000 Received: (qmail 72648 invoked by uid 500); 18 Apr 2010 15:06:16 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 72616 invoked by uid 500); 18 Apr 2010 15:06:16 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 72609 invoked by uid 99); 18 Apr 2010 15:06:16 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Apr 2010 15:06:16 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of bpendleton.derby@gmail.com designates 209.85.217.228 as permitted sender) Received: from [209.85.217.228] (HELO mail-gx0-f228.google.com) (209.85.217.228) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Apr 2010 15:06:07 +0000 Received: by gxk28 with SMTP id 28so2547376gxk.7 for ; Sun, 18 Apr 2010 08:05:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=w+NyPKj1vfqD3lf+Y7kcC+Ke0fzNk0G06LQb/wfnbXQ=; b=lq/zGU1BGhyGGNLvw2RSvBR7bw1jdh8tRKAXnNlxE6wg/aNdtnKgL6x8bdBKhdPMRa VrZViN5cYb8jVTvUWdjJQJCzZNV88zs3UtrgIk7C4RGi2bnZayWS+9XhYj7dHWbetAlj /u4H3/Gh/FUJHgAxW7llw1TNY+wPQR1oYTgbw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=vhPkGdabxIMVFxG+9VEyUo3caRhCi/saWZUf8i1pV5qih+1NomgTATOcjn9WeEHKYO D1YChSG5OWnHgAuRjivYes4BtRC8/+XosnKB6YirseuLN+rH4cIoj3ejyLINJhZ55ulD FVHQVUD+PWRfsbEXS8NzuJLsy4pHJN61Z2/+E= Received: by 10.101.147.32 with SMTP id z32mr4185097ann.106.1271603145812; Sun, 18 Apr 2010 08:05:45 -0700 (PDT) Received: from [192.168.0.103] (c-67-170-231-73.hsd1.ca.comcast.net [67.170.231.73]) by mx.google.com with ESMTPS id 4sm1324077ywd.13.2010.04.18.08.05.44 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 18 Apr 2010 08:05:45 -0700 (PDT) Message-ID: <4BCB1FC7.1060302@gmail.com> Date: Sun, 18 Apr 2010 08:05:43 -0700 From: Bryan Pendleton User-Agent: Thunderbird 2.0.0.24 (X11/20100411) MIME-Version: 1.0 To: derby-dev@db.apache.org Subject: Re: Checking an Expressions References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Nirmal Fernando wrote: > How can we check whether a particular ValueNode is an "expression" (eg: i*2) ?. > > *Note: We can check "ValueNode instance of ColumnReference" to check > whether it is a column (eg: i). I think that every ValueNode is an expression of some sort. Consider: select name from employee; select year_hired - 1900 from employee; select max(salary) from employee; select current_date from employee; select first_name || ' ' || last_name from employee; All of these will result in various ValueNode instances being constructed. Some are simple ColumnReference nodes. Others are more complex expressions. Unfortunately (or fortunately, depending on how you look at it), ValueNode is an extremely general-purpose class in Derby, and there are a large number of particular sub-classes of ValueNode that are of interest. It so happens that the case of "a simple direct reference to a column in this table" is extremely common, and has a number of optimizations that we perform, and so you see code in Derby that says if (expression instanceof ColumnReference) quite commonly. However, there are many sub-classes of ValueNode. Consider that these classes are just some of the *direct* sub-classes of ValueNode: BaseColumnNode.java:public class BaseColumnNode extends ValueNode BinaryListOperatorNode.java:public abstract class BinaryListOperatorNode extends ValueNode BinaryOperatorNode.java:public class BinaryOperatorNode extends ValueNode CastNode.java:public class CastNode extends ValueNode CoalesceFunctionNode.java:public class CoalesceFunctionNode extends ValueNode ColumnReference.java:public class ColumnReference extends ValueNode ConditionalNode.java:public class ConditionalNode extends ValueNode ConstantNode.java:abstract class ConstantNode extends ValueNode CurrentDatetimeOperatorNode.java:public class CurrentDatetimeOperatorNode extends ValueNode { CurrentRowLocationNode.java:public class CurrentRowLocationNode extends ValueNode DefaultNode.java:public class DefaultNode extends ValueNode GenerationClauseNode.java:public class GenerationClauseNode extends ValueNode JavaToSQLValueNode.java:public class JavaToSQLValueNode extends ValueNode NextSequenceNode.java:public class NextSequenceNode extends ValueNode { ParameterNode.java:public class ParameterNode extends ValueNode ResultColumn.java:public class ResultColumn extends ValueNode SpecialFunctionNode.java:public class SpecialFunctionNode extends ValueNode SubqueryNode.java:public class SubqueryNode extends ValueNode TernaryOperatorNode.java:public class TernaryOperatorNode extends ValueNode UnaryOperatorNode.java:public class UnaryOperatorNode extends ValueNode VirtualColumnNode.java:public class VirtualColumnNode extends ValueNode And many of these classes have further sub-classes of them. You might finding it helpful to use the parse-tree-printing support in Derby to dump out the parse tree from several sample queries and have a look at how the parse trees are put together. I think that you can use the ASTVisitor support that was added in DERBY-4415 (https://issues.apache.org/jira/browse/DERBY-4415) and DERBY-791 (https://issues.apache.org/jira/browse/DERBY-791) to view the parse trees. thanks, bryan