/* // $Id: //guest/julian_hyde/mondrian/src/main/mondrian/olap/ExpBase.java#1 $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. // (C) Copyright 1999-2002 Kana Software, Inc. and others. // All Rights Reserved. // You must accept the terms of that agreement to use this software. // // jhyde, 20 January, 1999 */ package mondrian.olap; import java.util.*; import java.io.*; /** * MDX expressions. **/ public abstract class ExpBase extends QueryPart implements Exp { public abstract Object clone(); static Exp[] cloneArray(Exp[] a) { Exp[] a2 = new Exp[a.length]; for (int i = 0; i < a.length; i++) a2[i] = (Exp) a[i].clone(); return a2; } public Cube getCube() { return getHierarchy().getCube(); } /** * Returns the dimension of a this expression, or null if no dimension is * defined. Applicable only to set expressions. * * <p>Example 1: * <blockquote><pre> * [Sales].children * </pre></blockquote> * has dimension <code>[Sales]</code>.</p> * * <p>Example 2: * <blockquote><pre> * order(except([Promotion Media].[Media Type].members, * {[Promotion Media].[Media Type].[No Media]}), * [Measures].[Unit Sales], DESC) * </pre></blockquote> * has dimension [Promotion Media].</p> * * <p>Example 3: * <blockquote><pre> * CrossJoin([Product].[Product Department].members, * [Gender].members) * </pre></blockquote> * has no dimension (well, actually it is [Product] x [Gender], but we * can't represent that, so we return null);</p> **/ public Dimension getDimension() { Hierarchy mdxHierarchy = getHierarchy(); if (mdxHierarchy != null) { return mdxHierarchy.getDimension(); } return null; } public Hierarchy getHierarchy() { return null; } public final boolean isSet() { int cat = getCategory(); return cat == CatSet || cat == CatTuple; } public final boolean isMember() { return getCategory() == CatMember; } public final boolean isElement() { int category = getCategory(); return isMember() || category == CatHierarchy || category == CatLevel || category == CatDimension; } public final boolean isParameter() { return getCategory() == CatParameter; } public final boolean isEmptySet() { if (this instanceof FunCall) { FunCall f = (FunCall) this; return f.isCallToSet() && f.args.length == 0; } else { return false; } } /** * Returns an array of {@link Member}s if this is a member or a tuple, * null otherwise. **/ public final Member[] isConstantTuple() { if (this instanceof Member) { return new Member[] {(Member) this}; } if (!(this instanceof FunCall)) { return null; } FunCall f = (FunCall) this; if (!f.isCallToTuple()) { return null; } for (int i = 0; i < f.args.length; i++) { if (!(f.args[i] instanceof Member)) { return null; } } Member[] members = new Member[f.args.length]; System.arraycopy(f.args, 0, members, 0, f.args.length); return members; } protected static boolean arrayUsesDimension(Exp[] exps, Dimension dim) { for (int i = 0; i < exps.length; i++) if (exps[i].usesDimension(dim)) return true; return false; } static Exp[] makeArray(Exp x) { Exp[] array = new Exp[x == null ? 0 : ((ExpBase) x).getChainLength()]; for (int i = 0; x != null; x = (Exp) ((ExpBase) x).next) { array[i++] = x; } return array; } static void unparseList( PrintWriter pw, Exp[] exps, String start, String end, ElementCallback callback) { pw.print(start); for (int i = 0; i < exps.length; i++) { if (i > 0) pw.print(", "); exps[i].unparse(pw, callback); } pw.print(end); } static void unparseList(PrintWriter pw, Exp[] exps, ElementCallback callback) { unparseList(pw, exps, "(", ")", callback); } public int addAtPosition(Exp e, int iPosition) { // Since this method has not been overridden for this type of // expression, we presume that the expression has a dimensionality of // 1. We therefore return 1 to indicate that we could not add the // expression, and that this expression has a dimensionality of 1. return 1; } public Object evaluate(Evaluator evaluator) { throw new Error("unsupported"); } public Object evaluateScalar(Evaluator evaluator) { Object o = evaluate(evaluator); if (o instanceof Member) { evaluator.setContext((Member) o); return evaluator.evaluateCurrent(); } else if (o instanceof Member[]) { evaluator.setContext((Member[]) o); return evaluator.evaluateCurrent(); } else { return o; } } } // End Exp.java
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 1499 | Julian Hyde |
Mondrian: Re-organize functions and type-checking Add mondrian.olap.fun package |
||
#1 | 1453 | Julian Hyde | mondrian: first source check-in |