def dimension(self, ast): refs = Parser.allrefs(self.cube.model.dimensions, self.cube.model.attributes) if ast not in refs: raise QueryException('Invalid drilldown: %r' % ast) if ast not in self.results: self.results.append(ast)
def field(self, ast): refs = [m.ref for m in self.cube.model.measures] + \ [d.ref for d in self.cube.model.dimensions] + \ [a.ref for a in self.cube.model.attributes] if ast not in refs: raise QueryException('Invalid field: %r' % ast) self.results.append(ast)
def parse(self, text): if isinstance(text, six.string_types): try: model.parse(text, start=self.start, semantics=self) return self.results except GrakoException, ge: raise QueryException(ge.message)
def order(self, ast): if isinstance(ast, six.string_types): ref, direction = ast, 'asc' else: ref, direction = ast[0], ast[2] if ref not in self.cube.model: raise QueryException('Invalid sorting criterion: %r' % ast) self.results.append((ref, direction))
def cut(self, ast): value = ast[2] if isinstance(value, six.string_types) and len(value.strip()) == 0: value = None # TODO: can you filter measures or aggregates? if ast[0] not in self.cube.model: raise QueryException('Invalid cut: %r' % ast[0]) self.results.append((ast[0], ast[1], value))
def field(self, ast): refs = Parser.allrefs(self.cube.model.measures, self.cube.model.dimensions, self.cube.model.attributes) if ast not in refs: raise QueryException('Invalid field: %r' % ast) self.results.append(ast)
def _check_type(self, ref, value): """ Checks whether the type of the cut value matches the type of the concept being cut, and raises a QueryException if it doesn't match """ if isinstance(value, list): return [self._check_type(ref, val) for val in value] model_type = self.cube.model[ref].datatype if model_type is None: return query_type = self._api_type(value) if query_type == model_type: return else: raise QueryException("Invalid value %r parsed as type '%s' " "for cut %s of type '%s'" % (value, query_type, ref, model_type))
def aggregate(self, ast): refs = [a.ref for a in self.cube.model.aggregates] if ast not in refs: raise QueryException('Invalid aggregate: %r' % ast) self.results.append(ast)
def dimension(self, ast): refs = [d.ref for d in self.cube.model.dimensions] + \ [a.ref for a in self.cube.model.attributes] if ast not in refs: raise QueryException('Invalid drilldown: %r' % ast) self.results.append(ast)