001/* 002// This software is subject to the terms of the Eclipse Public License v1.0 003// Agreement, available at the following URL: 004// http://www.eclipse.org/legal/epl-v10.html. 005// You must accept the terms of that agreement to use this software. 006// 007// Copyright (C) 2005-2005 Julian Hyde 008// Copyright (C) 2005-2009 Pentaho 009// All Rights Reserved. 010*/ 011package mondrian.olap; 012 013import mondrian.mdx.ParameterExpr; 014import mondrian.olap.fun.Resolver; 015import mondrian.olap.type.Type; 016 017import java.util.List; 018 019/** 020 * Provides context necessary to resolve identifiers to objects, function 021 * calls to specific functions. 022 * 023 * <p>An expression calls {@link #validate} on each of its children, 024 * which in turn calls {@link Exp#accept}. 025 * 026 * @author jhyde 027 */ 028public interface Validator { 029 /** 030 * Returns the {@link Query} which is being validated. 031 */ 032 Query getQuery(); 033 034 /** 035 * Validates an expression, and returns the expression it resolves to. 036 * 037 * @param exp Expression to validate 038 * @param scalar Whether the context requires that the expression is 039 * evaluated to a value, as opposed to a tuple 040 */ 041 Exp validate(Exp exp, boolean scalar); 042 043 /** 044 * Validates a usage of a parameter. 045 * 046 * <p>It must resolve to the same object (although sub-objects may change). 047 */ 048 void validate(ParameterExpr parameterExpr); 049 050 /** 051 * Validates a child member property. 052 * 053 * <p>It must resolve to the same object (although sub-objects may change). 054 */ 055 void validate(MemberProperty memberProperty); 056 057 /** 058 * Validates an axis. 059 * 060 * It must resolve to the same object (although sub-objects may change). 061 */ 062 void validate(QueryAxis axis); 063 064 /** 065 * Validates a formula. 066 * 067 * It must resolve to the same object (although sub-objects may change). 068 */ 069 void validate(Formula formula); 070 071 /** 072 * Returns whether the current context requires an expression. 073 */ 074 boolean requiresExpression(); 075 076 /** 077 * Returns whether we can convert an argument to a parameter type. 078 * 079 * @param ordinal argument ordinal 080 * @param fromExp argument type 081 * @param to parameter type 082 * @param conversions List of conversions performed; 083 * method adds an element for each non-trivial conversion (for 084 * example, converting a member to a level). 085 * @return Whether we can convert an argument to a parameter type 086 */ 087 boolean canConvert( 088 int ordinal, 089 Exp fromExp, 090 int to, 091 List<Resolver.Conversion> conversions); 092 093 /** 094 * Returns the table of function and operator definitions. 095 */ 096 FunTable getFunTable(); 097 098 /** 099 * Creates or retrieves the parameter corresponding to a "Parameter" or 100 * "ParamRef" function call. 101 */ 102 Parameter createOrLookupParam( 103 boolean definition, 104 String name, 105 Type type, 106 Exp defaultExp, 107 String description); 108 109 /** 110 * Resolves a function call to a particular function. If the function is 111 * overloaded, returns as precise a match to the argument types as 112 * possible. 113 */ 114 FunDef getDef( 115 Exp[] args, 116 String name, 117 Syntax syntax); 118 119 /** 120 * Whether to resolve function name and arguments to a function definition 121 * each time a node is validated, not just the first time. 122 * 123 * <p>Default implementation returns {@code false}. 124 * 125 * @return whether to resolve function each time 126 */ 127 boolean alwaysResolveFunDef(); 128 129 /** 130 * Returns the schema reader with which to resolve names of MDX objects 131 * (dimensions, hierarchies, levels, members, named sets). 132 * 133 * <p>The schema reader is initially in the context of the query's cube, 134 * and during a traversal it may change if named sets are introduced using 135 * the 'expr AS alias' construct. 136 * 137 * @return Schema reader 138 */ 139 SchemaReader getSchemaReader(); 140} 141 142// End Validator.java