def reduce_FROM_Identifier_EXPRESSION(self, *kids): lang = commondl._parse_language(kids[1]) if lang != qlast.Language.SQL: raise EdgeQLSyntaxError( f'{lang} language is not supported in FROM clause', context=kids[1].context) from None self.val = qlast.OperatorCode(language=lang)
def reduce_FROM_Identifier_FUNCTION_BaseStringConstant(self, *kids): lang = commondl._parse_language(kids[1]) if lang != qlast.Language.SQL: raise EdgeQLSyntaxError( f'{lang} language is not supported in FROM FUNCTION clause', context=kids[1].context) from None self.val = qlast.OperatorCode(language=lang, from_function=kids[3].val.value)
def _apply_field_ast( self, schema: s_schema.Schema, context: sd.CommandContext, node: qlast.DDLOperation, op: sd.AlterObjectProperty, ) -> None: assert isinstance(node, qlast.CreateOperator) new_value: Any = op.new_value if op.property == 'return_type': node.returning = utils.typeref_to_ast(schema, new_value) elif op.property == 'return_typemod': node.returning_typemod = new_value elif op.property == 'code': if node.code is None: node.code = qlast.OperatorCode() node.code.code = new_value elif op.property == 'language': if node.code is None: node.code = qlast.OperatorCode() node.code.language = new_value elif op.property == 'from_function' and new_value: if node.code is None: node.code = qlast.OperatorCode() node.code.from_function = new_value elif op.property == 'from_expr' and new_value: if node.code is None: node.code = qlast.OperatorCode() node.code.from_expr = new_value elif op.property == 'from_operator' and new_value: if node.code is None: node.code = qlast.OperatorCode() node.code.from_operator = tuple(new_value) else: super()._apply_field_ast(schema, context, node, op)
def reduce_FROM_Identifier_OPERATOR_BaseStringConstant(self, *kids): lang = commondl._parse_language(kids[1]) if lang != qlast.Language.SQL: raise EdgeQLSyntaxError( f'{lang} language is not supported in FROM OPERATOR clause', context=kids[1].context) from None sql_operator = kids[3].val.value m = re.match(r'([^(]+)(?:\((\w*(?:,\s*\w*)*)\))?', sql_operator) if not m: raise EdgeQLSyntaxError( f'invalid syntax for FROM OPERATOR clause', context=kids[3].context) from None sql_operator = (m.group(1),) if m.group(2): operands = tuple(op.strip() for op in m.group(2).split(',')) sql_operator += operands self.val = qlast.OperatorCode( language=lang, from_operator=sql_operator)
def _process_operator_body(self, block, abstract: bool=False): props = {} commands = [] from_operator = None from_function = None from_expr = False code = None for node in block.val: if isinstance(node, qlast.OperatorCode): if abstract: raise errors.InvalidOperatorDefinitionError( 'unexpected FROM clause in abstract ' 'operator definition', context=node.context, ) if node.from_function: if from_function is not None: raise errors.InvalidOperatorDefinitionError( 'more than one FROM FUNCTION clause', context=node.context) from_function = node.from_function elif node.from_operator: if from_operator is not None: raise errors.InvalidOperatorDefinitionError( 'more than one FROM OPERATOR clause', context=node.context) from_operator = node.from_operator elif node.code: if code is not None: raise errors.InvalidOperatorDefinitionError( 'more than one FROM <code> clause', context=node.context) code = node.code else: # FROM SQL EXPRESSION from_expr = True else: commands.append(node) if not abstract: if (code is None and from_operator is None and from_function is None and not from_expr): raise errors.InvalidOperatorDefinitionError( 'CREATE OPERATOR requires at least one FROM clause', context=block.context) else: if from_expr and (from_operator or from_function or code): raise errors.InvalidOperatorDefinitionError( 'FROM SQL EXPRESSION is mutually exclusive with other ' 'FROM variants', context=block.context) props['code'] = qlast.OperatorCode( language=qlast.Language.SQL, from_function=from_function, from_operator=from_operator, from_expr=from_expr, code=code, ) if commands: props['commands'] = commands return props