001 /* 002 // $Id: //open/mondrian/src/main/mondrian/olap/type/Type.java#7 $ 003 // This software is subject to the terms of the Common Public License 004 // Agreement, available at the following URL: 005 // http://www.opensource.org/licenses/cpl.html. 006 // Copyright (C) 2005-2008 Julian Hyde 007 // All Rights Reserved. 008 // You must accept the terms of that agreement to use this software. 009 */ 010 package mondrian.olap.type; 011 012 import mondrian.olap.Dimension; 013 import mondrian.olap.Hierarchy; 014 import mondrian.olap.Level; 015 016 /** 017 * Type of an MDX expression. 018 * 019 * @author jhyde 020 * @since Feb 17, 2005 021 * @version $Id: //open/mondrian/src/main/mondrian/olap/type/Type.java#7 $ 022 */ 023 public interface Type { 024 /** 025 * Returns whether this type contains a given dimension.<p/> 026 * 027 * For example: 028 * <ul> 029 * <li><code>DimensionType([Gender])</code> uses only the 030 * <code>[Gender]</code> dimension.</li> 031 * <li><code>TupleType(MemberType([Gender]), MemberType([Store]))</code> 032 * uses <code>[Gender]</code> and <code>[Store]</code> 033 * dimensions.</li> 034 * </ul><p/> 035 * 036 * The <code>definitely</code> parameter comes into play when the 037 * dimensional information is incomplete. For example, when applied to 038 * <code>TupleType(MemberType(null), MemberType([Store]))</code>, 039 * <code>usesDimension([Gender], false)</code> returns true because it 040 * is possible that the expression returns a member of the 041 * <code>[Gender]</code> dimension; but 042 * <code>usesDimension([Gender], true)</code> returns true because it 043 * is possible that the expression returns a member of the 044 * <code>[Gender]</code> dimension. 045 * 046 * @param dimension Dimension 047 * @param definitely If true, returns true only if this type definitely 048 * uses the dimension 049 * 050 * @return whether this Type uses the given Dimension 051 */ 052 boolean usesDimension(Dimension dimension, boolean definitely); 053 054 /** 055 * Returns the Dimension of this Type, or null if not known. 056 * If not applicable, throws. 057 * 058 * @return the Dimension of this Type, or null if not known. 059 */ 060 Dimension getDimension(); 061 062 /** 063 * Returns the Hierarchy of this Type, or null if not known. 064 * If not applicable, throws. 065 * 066 * @return the Hierarchy of this type, or null if not known 067 */ 068 Hierarchy getHierarchy(); 069 070 /** 071 * Returns the Level of this Type, or null if not known. 072 * If not applicable, throws. 073 * 074 * @return the Level of this Type 075 */ 076 Level getLevel(); 077 078 /** 079 * Returns a Type which is more general than this and the given Type. 080 * The type returned is broad enough to hold any value of either type, 081 * but no broader. If there is no such type, returns null. 082 * 083 * <p>Some examples:<ul> 084 * <li>The common type for StringType and NumericType is ScalarType. 085 * <li>The common type for NumericType and DecimalType(4, 2) is 086 * NumericType. 087 * <li>DimensionType and NumericType have no common type. 088 * </ul></p> 089 * 090 * <p>If <code>conversionCount</code> is not null, implicit conversions 091 * such as HierarchyType to DimensionType are considered; the parameter 092 * is incremented by the number of conversions performed. 093 * 094 * <p>Some examples:<ul> 095 * <li>The common type for HierarchyType(hierarchy=Time.Weekly) 096 * and LevelType(dimension=Time), if conversions are allowed, is 097 * HierarchyType(dimension=Time). 098 * </ul> 099 * 100 * <p>One use of common types is to determine the types of the arguments 101 * to the <code>Iif</code> function. For example, the call 102 * 103 * <blockquote><code>Iif(1 > 2, [Measures].[Unit Sales], 5)</code></blockquote> 104 * 105 * has type ScalarType, because DecimalType(-1, 0) is a subtype of 106 * ScalarType, and MeasureType can be converted implicitly to ScalarType. 107 * 108 * @param type Type 109 * 110 * @param conversionCount Number of conversions; output parameter that is 111 * incremented each time a conversion is performed; if null, conversions 112 * are not considered 113 * 114 * @return More general type 115 */ 116 Type computeCommonType(Type type, int[] conversionCount); 117 } 118 119 // End Type.java