signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def __eq__(self, other): | <EOL>return (type(self) == type(other) and<EOL>self.fold_scope_location == other.fold_scope_location and<EOL>self.field_type.is_same_type(other.field_type))<EOL> | Return True if the given object is equal to this one, and False otherwise. | f12662:c6:m4 |
def __ne__(self, other): | return not self.__eq__(other)<EOL> | Check another object for non-equality against this one. | f12662:c6:m5 |
def __init__(self, fold_scope_location): | super(FoldCountContextField, self).__init__(fold_scope_location)<EOL>self.fold_scope_location = fold_scope_location<EOL>self.validate()<EOL> | Construct a new FoldCountContextField object for this fold.
Args:
fold_scope_location: FoldScopeLocation specifying the fold whose size is being output.
Returns:
new FoldCountContextField object | f12662:c7:m0 |
def validate(self): | if not isinstance(self.fold_scope_location, FoldScopeLocation):<EOL><INDENT>raise TypeError(u'<STR_LIT>'.format(<EOL>type(self.fold_scope_location), self.fold_scope_location))<EOL><DEDENT>if self.fold_scope_location.field != COUNT_META_FIELD_NAME:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'<EOL>.form... | Validate that the FoldCountContextField is correctly representable. | f12662:c7:m1 |
def to_match(self): | self.validate()<EOL>mark_name, _ = self.fold_scope_location.get_location_name()<EOL>validate_safe_string(mark_name)<EOL>template = u'<STR_LIT>'<EOL>template_data = {<EOL>'<STR_LIT>': mark_name,<EOL>}<EOL>return template % template_data<EOL> | Return a unicode object with the MATCH representation of this expression. | f12662:c7:m2 |
def to_gremlin(self): | raise NotImplementedError()<EOL> | Must never be called. | f12662:c7:m3 |
def __init__(self, location): | super(ContextFieldExistence, self).__init__(location)<EOL>self.location = location<EOL>self.validate()<EOL> | Construct a new ContextFieldExistence object for a vertex field from the global context.
Args:
location: Location, specifying where the field was declared. Must point to a vertex.
Returns:
new ContextFieldExistence expression which evaluates to True iff the vertex exists | f12662:c8:m0 |
def validate(self): | if not isinstance(self.location, Location):<EOL><INDENT>raise TypeError(u'<STR_LIT>'.format(<EOL>type(self.location).__name__, self.location))<EOL><DEDENT>if self.location.field:<EOL><INDENT>raise ValueError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(self.location))<EOL><DEDENT> | Validate that the ContextFieldExistence is correctly representable. | f12662:c8:m1 |
def to_match(self): | raise AssertionError(u'<STR_LIT>'.format(self))<EOL> | Must not be used -- ContextFieldExistence must be lowered during the IR lowering step. | f12662:c8:m2 |
def to_gremlin(self): | raise AssertionError(u'<STR_LIT>'.format(self))<EOL> | Must not be used -- ContextFieldExistence must be lowered during the IR lowering step. | f12662:c8:m3 |
def __init__(self, operator, inner_expression): | super(UnaryTransformation, self).__init__(operator, inner_expression)<EOL>self.operator = operator<EOL>self.inner_expression = inner_expression<EOL> | Construct a UnaryExpression that modifies the given inner expression. | f12662:c9:m0 |
def validate(self): | _validate_operator_name(self.operator, UnaryTransformation.SUPPORTED_OPERATORS)<EOL>if not isinstance(self.inner_expression, Expression):<EOL><INDENT>raise TypeError(u'<STR_LIT>'.format(<EOL>type(self.inner_expression).__name__, self.inner_expression))<EOL><DEDENT> | Validate that the UnaryTransformation is correctly representable. | f12662:c9:m1 |
def visit_and_update(self, visitor_fn): | new_inner = self.inner_expression.visit_and_update(visitor_fn)<EOL>if new_inner is not self.inner_expression:<EOL><INDENT>return visitor_fn(UnaryTransformation(self.operator, new_inner))<EOL><DEDENT>else:<EOL><INDENT>return visitor_fn(self)<EOL><DEDENT> | Create an updated version (if needed) of UnaryTransformation via the visitor pattern. | f12662:c9:m2 |
def to_match(self): | self.validate()<EOL>translation_table = {<EOL>u'<STR_LIT:size>': u'<STR_LIT>',<EOL>}<EOL>match_operator = translation_table.get(self.operator)<EOL>if not match_operator:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(self.operator, self))<EOL><DEDENT>template = u'<STR_LIT>'<EOL>args = {<EOL>'<STR... | Return a unicode object with the MATCH representation of this UnaryTransformation. | f12662:c9:m3 |
def to_gremlin(self): | translation_table = {<EOL>u'<STR_LIT:size>': u'<STR_LIT>',<EOL>}<EOL>gremlin_operator = translation_table.get(self.operator)<EOL>if not gremlin_operator:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(self.operator, self))<EOL><DEDENT>template = u'<STR_LIT>'<EOL>args = {<EOL>'<STR_LIT>': self.inn... | Return a unicode object with the Gremlin representation of this expression. | f12662:c9:m4 |
def __init__(self, operator, left, right): | super(BinaryComposition, self).__init__(operator, left, right)<EOL>self.operator = operator<EOL>self.left = left<EOL>self.right = right<EOL>self.validate()<EOL> | Construct an expression that connects two expressions with an operator.
Args:
operator: unicode, specifying where the field was declared
left: Expression on the left side of the binary operator
right: Expression on the right side of the binary operator
Returns:
... | f12662:c10:m0 |
def validate(self): | _validate_operator_name(self.operator, BinaryComposition.SUPPORTED_OPERATORS)<EOL>if not isinstance(self.left, Expression):<EOL><INDENT>raise TypeError(u'<STR_LIT>'.format(<EOL>type(self.left).__name__, self.left, self))<EOL><DEDENT>if not isinstance(self.right, Expression):<EOL><INDENT>raise TypeError(u'<STR_LIT>'.for... | Validate that the BinaryComposition is correctly representable. | f12662:c10:m1 |
def visit_and_update(self, visitor_fn): | new_left = self.left.visit_and_update(visitor_fn)<EOL>new_right = self.right.visit_and_update(visitor_fn)<EOL>if new_left is not self.left or new_right is not self.right:<EOL><INDENT>return visitor_fn(BinaryComposition(self.operator, new_left, new_right))<EOL><DEDENT>else:<EOL><INDENT>return visitor_fn(self)<EOL><DEDEN... | Create an updated version (if needed) of BinaryComposition via the visitor pattern. | f12662:c10:m2 |
def to_match(self): | self.validate()<EOL>regular_operator_format = '<STR_LIT>'<EOL>inverted_operator_format = '<STR_LIT>' <EOL>intersects_operator_format = '<STR_LIT>'<EOL>if any((isinstance(self.left, Literal) and self.left.value is None,<EOL>isinstance(self.right, Literal) and self.right.value is None)):<EOL><INDENT>translation_table = ... | Return a unicode object with the MATCH representation of this BinaryComposition. | f12662:c10:m3 |
def to_gremlin(self): | self.validate()<EOL>immediate_operator_format = u'<STR_LIT>'<EOL>dotted_operator_format = u'<STR_LIT>'<EOL>intersects_operator_format = u'<STR_LIT>'<EOL>translation_table = {<EOL>u'<STR_LIT:=>': (u'<STR_LIT>', immediate_operator_format),<EOL>u'<STR_LIT>': (u'<STR_LIT>', immediate_operator_format),<EOL>u'<STR_LIT>': (u'... | Return a unicode object with the Gremlin representation of this expression. | f12662:c10:m4 |
def __init__(self, predicate, if_true, if_false): | super(TernaryConditional, self).__init__(predicate, if_true, if_false)<EOL>self.predicate = predicate<EOL>self.if_true = if_true<EOL>self.if_false = if_false<EOL>self.validate()<EOL> | Construct an expression that evaluates a predicate and returns one of two results.
Args:
predicate: Expression to evaluate, and based on which to choose the returned value
if_true: Expression to return if the predicate was true
if_false: Expression to return if the predicate... | f12662:c11:m0 |
def validate(self): | if not isinstance(self.predicate, Expression):<EOL><INDENT>raise TypeError(u'<STR_LIT>'.format(<EOL>type(self.predicate).__name__, self.predicate))<EOL><DEDENT>if not isinstance(self.if_true, Expression):<EOL><INDENT>raise TypeError(u'<STR_LIT>'.format(<EOL>type(self.if_true).__name__, self.if_true))<EOL><DEDENT>if not... | Validate that the TernaryConditional is correctly representable. | f12662:c11:m1 |
def visit_and_update(self, visitor_fn): | new_predicate = self.predicate.visit_and_update(visitor_fn)<EOL>new_if_true = self.if_true.visit_and_update(visitor_fn)<EOL>new_if_false = self.if_false.visit_and_update(visitor_fn)<EOL>if any((new_predicate is not self.predicate,<EOL>new_if_true is not self.if_true,<EOL>new_if_false is not self.if_false)):<EOL><INDENT... | Create an updated version (if needed) of TernaryConditional via the visitor pattern. | f12662:c11:m2 |
def to_match(self): | self.validate()<EOL>def visitor_fn(expression):<EOL><INDENT>"""<STR_LIT>"""<EOL>if isinstance(expression, TernaryConditional):<EOL><INDENT>raise ValueError(u'<STR_LIT>'<EOL>u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(expression, self))<EOL><DEDENT>return expression<EOL><DEDENT>self.predicate.visit_and_update(visitor_fn)<EOL>f... | Return a unicode object with the MATCH representation of this TernaryConditional. | f12662:c11:m3 |
def to_gremlin(self): | self.validate()<EOL>return u'<STR_LIT>'.format(<EOL>predicate=self.predicate.to_gremlin(),<EOL>if_true=self.if_true.to_gremlin(),<EOL>if_false=self.if_false.to_gremlin())<EOL> | Return a unicode object with the Gremlin representation of this expression. | f12662:c11:m4 |
def _get_vertex_location_name(location): | mark_name, field_name = location.get_location_name()<EOL>if field_name is not None:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'.format(location))<EOL><DEDENT>return mark_name<EOL> | Get the location name from a location that is expected to point to a vertex. | f12663:m0 |
def _first_step_to_match(match_step): | parts = []<EOL>if match_step.root_block is not None:<EOL><INDENT>if not isinstance(match_step.root_block, QueryRoot):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(match_step.root_block, match_step))<EOL><DEDENT>match_step.root_block.validate()<EOL>start_class = get_only_element_from_collection(... | Transform the very first MATCH step into a MATCH query string. | f12663:m1 |
def _subsequent_step_to_match(match_step): | if not isinstance(match_step.root_block, (Traverse, Recurse)):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(match_step.root_block, match_step))<EOL><DEDENT>is_recursing = isinstance(match_step.root_block, Recurse)<EOL>match_step.root_block.validate()<EOL>traversal_command = u'<STR_LIT>' % (matc... | Transform any subsequent (non-first) MATCH step into a MATCH query string. | f12663:m2 |
def _represent_match_traversal(match_traversal): | output = []<EOL>output.append(_first_step_to_match(match_traversal[<NUM_LIT:0>]))<EOL>for step in match_traversal[<NUM_LIT:1>:]:<EOL><INDENT>output.append(_subsequent_step_to_match(step))<EOL><DEDENT>return u'<STR_LIT>'.join(output)<EOL> | Emit MATCH query code for an entire MATCH traversal sequence. | f12663:m3 |
def _represent_fold(fold_location, fold_ir_blocks): | start_let_template = u'<STR_LIT>'<EOL>traverse_edge_template = u'<STR_LIT>'<EOL>base_template = start_let_template + traverse_edge_template<EOL>edge_direction, edge_name = fold_location.get_first_folded_edge()<EOL>mark_name, _ = fold_location.get_location_name()<EOL>base_location_name, _ = fold_location.base_location.g... | Emit a LET clause corresponding to the IR blocks for a @fold scope. | f12663:m4 |
def _construct_output_to_match(output_block): | output_block.validate()<EOL>selections = (<EOL>u'<STR_LIT>' % (output_block.fields[key].to_match(), key)<EOL>for key in sorted(output_block.fields.keys()) <EOL>)<EOL>return u'<STR_LIT>' % (u'<STR_LIT:U+002CU+0020>'.join(selections),)<EOL> | Transform a ConstructResult block into a MATCH query string. | f12663:m5 |
def _construct_where_to_match(where_block): | if where_block.predicate == TrueLiteral:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>.format(where_block))<EOL><DEDENT>return u'<STR_LIT>' + where_block.predicate.to_match()<EOL> | Transform a Filter block into a MATCH query string. | f12663:m6 |
def emit_code_from_single_match_query(match_query): | query_data = deque([u'<STR_LIT>'])<EOL>if not match_query.match_traversals:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(match_query.match_traversals, match_query))<EOL><DEDENT>match_traversal_data = [<EOL>_represent_match_traversal(x)<EOL>for x in match_query.match_traversals<EOL>]<EOL>query_d... | Return a MATCH query string from a list of IR blocks. | f12663:m7 |
def emit_code_from_multiple_match_queries(match_queries): | optional_variable_base_name = '<STR_LIT>'<EOL>union_variable_name = '<STR_LIT>'<EOL>query_data = deque([u'<STR_LIT>', union_variable_name, u'<STR_LIT:)>', u'<STR_LIT>'])<EOL>optional_variables = []<EOL>sub_queries = [emit_code_from_single_match_query(match_query)<EOL>for match_query in match_queries]<EOL>for (i, sub_qu... | Return a MATCH query string from a list of MatchQuery namedtuples. | f12663:m8 |
def emit_code_from_ir(compound_match_query, compiler_metadata): | <EOL>match_queries = compound_match_query.match_queries<EOL>if len(match_queries) == <NUM_LIT:1>:<EOL><INDENT>query_string = emit_code_from_single_match_query(match_queries[<NUM_LIT:0>])<EOL><DEDENT>elif len(match_queries) > <NUM_LIT:1>:<EOL><INDENT>query_string = emit_code_from_multiple_match_queries(match_queries)<EO... | Return a MATCH query string from a CompoundMatchQuery. | f12663:m9 |
def emit_code_from_ir(ir_blocks, compiler_metadata): | gremlin_steps = (<EOL>block.to_gremlin()<EOL>for block in ir_blocks<EOL>)<EOL>non_empty_steps = (<EOL>step<EOL>for step in gremlin_steps<EOL>if step<EOL>)<EOL>return u'<STR_LIT:.>'.join(non_empty_steps)<EOL> | Return a MATCH query string from a list of IR blocks. | f12664:m0 |
def is_in_fold_innermost_scope(context): | return CONTEXT_FOLD_INNERMOST_SCOPE in context<EOL> | Return True if the current context is within a scope marked @fold. | f12665:m0 |
def unmark_fold_innermost_scope(context): | del context[CONTEXT_FOLD_INNERMOST_SCOPE]<EOL> | Remove the context mark signaling an innermost fold scope. | f12665:m1 |
def set_fold_innermost_scope(context): | context[CONTEXT_FOLD_INNERMOST_SCOPE] = True<EOL> | Set a mark indicating the innermost scope of a fold scope. | f12665:m2 |
def is_in_fold_scope(context): | return CONTEXT_FOLD in context<EOL> | Return True if the current context is within a scope marked @fold. | f12665:m3 |
def get_context_fold_info(context): | return context[CONTEXT_FOLD]<EOL> | Return the fold info stored in the context. | f12665:m4 |
def unmark_context_fold_scope(context): | del context[CONTEXT_FOLD]<EOL> | Return the context mark signaling the presence of a scope marked @fold. | f12665:m5 |
def set_fold_scope_data(context, data): | context[CONTEXT_FOLD] = data<EOL> | Set fold scope data in the context. | f12665:m6 |
def has_fold_count_filter(context): | return CONTEXT_FOLD_HAS_COUNT_FILTER in context<EOL> | Return True if the current context contains a filter on the _x_count field. | f12665:m7 |
def unmark_fold_count_filter(context): | del context[CONTEXT_FOLD_HAS_COUNT_FILTER]<EOL> | Remove the context mark signaling the existence of a fold count filter. | f12665:m8 |
def set_fold_count_filter(context): | context[CONTEXT_FOLD_HAS_COUNT_FILTER] = True<EOL> | Set a mark indicating the presence of a filter on a fold _x_count field. | f12665:m9 |
def is_in_optional_scope(context): | return CONTEXT_OPTIONAL in context<EOL> | Return True if the current context is within a scope marked @optional. | f12665:m10 |
def get_optional_scope_or_none(context): | return context.get(CONTEXT_OPTIONAL, None)<EOL> | Return the optional scope data recorded in the context, or None if no such data. | f12665:m11 |
def set_optional_scope_data(context, data): | context[CONTEXT_OPTIONAL] = data<EOL> | Set optional scope data in the context. | f12665:m12 |
def unmark_optional_scope(context): | del context[CONTEXT_OPTIONAL]<EOL> | Remove the context mark signaling the existence of an optional scope. | f12665:m13 |
def set_output_source_data(context, data): | context[CONTEXT_OUTPUT_SOURCE] = data<EOL> | Set output source data in the context. | f12665:m14 |
def has_encountered_output_source(context): | return CONTEXT_OUTPUT_SOURCE in context<EOL> | Return True if the current context has already encountered an @output_source directive. | f12665:m15 |
def validate_context_for_visiting_vertex_field(parent_location, vertex_field_name, context): | if is_in_fold_innermost_scope(context):<EOL><INDENT>raise GraphQLCompilationError(<EOL>u'<STR_LIT>'<EOL>u'<STR_LIT>'<EOL>.format(COUNT_META_FIELD_NAME, parent_location, vertex_field_name))<EOL><DEDENT> | Ensure that the current context allows for visiting a vertex field. | f12665:m16 |
def scalar_leaf_only(operator): | def decorator(f):<EOL><INDENT>"""<STR_LIT>"""<EOL>@wraps(f)<EOL>def wrapper(filter_operation_info, context, parameters, *args, **kwargs):<EOL><INDENT>"""<STR_LIT>"""<EOL>if '<STR_LIT>' in kwargs:<EOL><INDENT>current_operator = kwargs['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>current_operator = operator<EOL><DEDENT>if ... | Ensure the filter function is only applied to scalar leaf types. | f12666:m0 |
def vertex_field_only(operator): | def decorator(f):<EOL><INDENT>"""<STR_LIT>"""<EOL>@wraps(f)<EOL>def wrapper(filter_operation_info, context, parameters, *args, **kwargs):<EOL><INDENT>"""<STR_LIT>"""<EOL>if '<STR_LIT>' in kwargs:<EOL><INDENT>current_operator = kwargs['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>current_operator = operator<EOL><DEDENT>if ... | Ensure the filter function is only applied to vertex field types. | f12666:m1 |
def takes_parameters(count): | def decorator(f):<EOL><INDENT>"""<STR_LIT>"""<EOL>@wraps(f)<EOL>def wrapper(filter_operation_info, location, context, parameters, *args, **kwargs):<EOL><INDENT>"""<STR_LIT>"""<EOL>if len(parameters) != count:<EOL><INDENT>raise GraphQLCompilationError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(count, len(parameters), paramete... | Ensure the filter function has "count" parameters specified. | f12666:m2 |
def _represent_argument(directive_location, context, argument, inferred_type): | <EOL>argument_name = argument[<NUM_LIT:1>:]<EOL>validate_safe_string(argument_name)<EOL>if is_variable_argument(argument):<EOL><INDENT>existing_type = context['<STR_LIT>'].get(argument_name, inferred_type)<EOL>if not inferred_type.is_same_type(existing_type):<EOL><INDENT>raise GraphQLCompilationError(u'<STR_LIT>'<EOL>u... | Return a two-element tuple that represents the argument to the directive being processed.
Args:
directive_location: Location where the directive is used.
context: dict, various per-compilation data (e.g. declared tags, whether the current block
is optional, etc.). May be mutated in... | f12666:m3 |
@scalar_leaf_only(u'<STR_LIT>')<EOL>@takes_parameters(<NUM_LIT:1>)<EOL>def _process_comparison_filter_directive(filter_operation_info, location,<EOL>context, parameters, operator=None): | comparison_operators = {u'<STR_LIT:=>', u'<STR_LIT>', u'<STR_LIT:>>', u'<STR_LIT:<>', u'<STR_LIT>', u'<STR_LIT>'}<EOL>if operator not in comparison_operators:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT:{}>'.format(comparison_operators, operator))<EOL><DEDENT>filtered_field_type = filter_operation_info... | Return a Filter basic block that performs the given comparison against the property field.
Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
of the field where the filter is to be applied.
location: Location where this fi... | f12666:m4 |
@vertex_field_only(u'<STR_LIT>')<EOL>@takes_parameters(<NUM_LIT:1>)<EOL>def _process_has_edge_degree_filter_directive(filter_operation_info, location, context, parameters): | if isinstance(filter_operation_info.field_ast, InlineFragment):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'<EOL>u'<STR_LIT:{}>'.format(filter_operation_info.field_ast))<EOL><DEDENT>filtered_field_name = filter_operation_info.field_name<EOL>if filtered_field_name is None or not is_vertex_field_name(fi... | Return a Filter basic block that checks the degree of the edge to the given vertex field.
Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
of the field where the filter is to be applied.
location: Location where this fil... | f12666:m5 |
@vertex_field_only(u'<STR_LIT>')<EOL>@takes_parameters(<NUM_LIT:1>)<EOL>def _process_name_or_alias_filter_directive(filter_operation_info, location, context, parameters): | filtered_field_type = filter_operation_info.field_type<EOL>if isinstance(filtered_field_type, GraphQLUnionType):<EOL><INDENT>raise GraphQLCompilationError(u'<STR_LIT>'<EOL>u'<STR_LIT:{}>'.format(filtered_field_type))<EOL><DEDENT>current_type_fields = filtered_field_type.fields<EOL>name_field = current_type_fields.get('... | Return a Filter basic block that checks for a match against an Entity's name or alias.
Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
of the field where the filter is to be applied.
location: Location where this filter... | f12666:m6 |
@scalar_leaf_only(u'<STR_LIT>')<EOL>@takes_parameters(<NUM_LIT:2>)<EOL>def _process_between_filter_directive(filter_operation_info, location, context, parameters): | filtered_field_type = filter_operation_info.field_type<EOL>filtered_field_name = filter_operation_info.field_name<EOL>argument_inferred_type = strip_non_null_from_type(filtered_field_type)<EOL>arg1_expression, arg1_non_existence = _represent_argument(<EOL>location, context, parameters[<NUM_LIT:0>], argument_inferred_ty... | Return a Filter basic block that checks that a field is between two values, inclusive.
Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
of the field where the filter is to be applied.
location: Location where this filter... | f12666:m7 |
@scalar_leaf_only(u'<STR_LIT>')<EOL>@takes_parameters(<NUM_LIT:1>)<EOL>def _process_in_collection_filter_directive(filter_operation_info, location, context, parameters): | filtered_field_type = filter_operation_info.field_type<EOL>filtered_field_name = filter_operation_info.field_name<EOL>argument_inferred_type = GraphQLList(strip_non_null_from_type(filtered_field_type))<EOL>argument_expression, non_existence_expression = _represent_argument(<EOL>location, context, parameters[<NUM_LIT:0>... | Return a Filter basic block that checks for a value's existence in a collection.
Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
of the field where the filter is to be applied.
location: Location where this filter is us... | f12666:m8 |
@scalar_leaf_only(u'<STR_LIT>')<EOL>@takes_parameters(<NUM_LIT:1>)<EOL>def _process_has_substring_filter_directive(filter_operation_info, location, context, parameters): | filtered_field_type = filter_operation_info.field_type<EOL>filtered_field_name = filter_operation_info.field_name<EOL>if not strip_non_null_from_type(filtered_field_type).is_same_type(GraphQLString):<EOL><INDENT>raise GraphQLCompilationError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(filtered_field_type))<EOL><DEDENT>argumen... | Return a Filter basic block that checks if the directive arg is a substring of the field.
Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
of the field where the filter is to be applied.
location: Location where this fil... | f12666:m9 |
@takes_parameters(<NUM_LIT:1>)<EOL>def _process_contains_filter_directive(filter_operation_info, location, context, parameters): | filtered_field_type = filter_operation_info.field_type<EOL>filtered_field_name = filter_operation_info.field_name<EOL>base_field_type = strip_non_null_from_type(filtered_field_type)<EOL>if not isinstance(base_field_type, GraphQLList):<EOL><INDENT>raise GraphQLCompilationError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(filter... | Return a Filter basic block that checks if the directive arg is contained in the field.
Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
of the field where the filter is to be applied.
location: Location where this filte... | f12666:m10 |
@takes_parameters(<NUM_LIT:1>)<EOL>def _process_intersects_filter_directive(filter_operation_info, location, context, parameters): | filtered_field_type = filter_operation_info.field_type<EOL>filtered_field_name = filter_operation_info.field_name<EOL>argument_inferred_type = strip_non_null_from_type(filtered_field_type)<EOL>if not isinstance(argument_inferred_type, GraphQLList):<EOL><INDENT>raise GraphQLCompilationError(u'<STR_LIT>'<EOL>u'<STR_LIT>'... | Return a Filter basic block that checks if the directive arg and the field intersect.
Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
of the field where the filter is to be applied.
location: Location where this filter ... | f12666:m11 |
def _get_filter_op_name_and_values(directive): | args = get_uniquely_named_objects_by_name(directive.arguments)<EOL>if '<STR_LIT>' not in args:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(directive))<EOL><DEDENT>if not isinstance(args['<STR_LIT:value>'].value, ListValue):<EOL><INDENT>raise GraphQLValidationError(u'<STR_LIT>'.format(directive... | Extract the (op_name, operator_params) tuple from a directive object. | f12666:m12 |
def is_filter_with_outer_scope_vertex_field_operator(directive): | if directive.name.value != '<STR_LIT>':<EOL><INDENT>return False<EOL><DEDENT>op_name, _ = _get_filter_op_name_and_values(directive)<EOL>return op_name in OUTER_SCOPE_VERTEX_FIELD_OPERATORS<EOL> | Return True if we have a filter directive whose operator applies to the outer scope. | f12666:m13 |
def process_filter_directive(filter_operation_info, location, context): | op_name, operator_params = _get_filter_op_name_and_values(filter_operation_info.directive)<EOL>non_comparison_filters = {<EOL>u'<STR_LIT>': _process_name_or_alias_filter_directive,<EOL>u'<STR_LIT>': _process_between_filter_directive,<EOL>u'<STR_LIT>': _process_in_collection_filter_directive,<EOL>u'<STR_LIT>': _process_... | Return a Filter basic block that corresponds to the filter operation in the directive.
Args:
filter_operation_info: FilterOperationInfo object, containing the directive and field info
of the field where the filter is to be applied.
location: Location where this filter... | f12666:m14 |
def lower_coerce_type_block_type_data(ir_blocks, type_equivalence_hints): | allowed_key_type_spec = (GraphQLInterfaceType, GraphQLObjectType)<EOL>allowed_value_type_spec = GraphQLUnionType<EOL>for key, value in six.iteritems(type_equivalence_hints):<EOL><INDENT>if (not isinstance(key, allowed_key_type_spec) or<EOL>not isinstance(value, allowed_value_type_spec)):<EOL><INDENT>msg = (u'<STR_LIT>'... | Rewrite CoerceType blocks to explicitly state which types are allowed in the coercion. | f12667:m0 |
def lower_coerce_type_blocks(ir_blocks): | new_ir_blocks = []<EOL>for block in ir_blocks:<EOL><INDENT>new_block = block<EOL>if isinstance(block, CoerceType):<EOL><INDENT>predicate = BinaryComposition(<EOL>u'<STR_LIT>', Literal(list(block.target_class)), LocalField('<STR_LIT>'))<EOL>new_block = Filter(predicate)<EOL><DEDENT>new_ir_blocks.append(new_block)<EOL><D... | Lower CoerceType blocks into Filter blocks with a type-check predicate. | f12667:m1 |
def rewrite_filters_in_optional_blocks(ir_blocks): | new_ir_blocks = []<EOL>optional_context_depth = <NUM_LIT:0><EOL>for block in ir_blocks:<EOL><INDENT>new_block = block<EOL>if isinstance(block, CoerceType):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(ir_blocks))<EOL><DEDENT>elif isinstance(block, Traverse) and block.optional:<EOL><INDENT>optio... | In optional contexts, add a check for null that allows non-existent optional data through.
Optional traversals in Gremlin represent missing optional data by setting the current vertex
to null until the exit from the optional scope. Therefore, filtering and type coercions
(which should have been lowered int... | f12667:m2 |
def _convert_folded_blocks(folded_ir_blocks): | new_folded_ir_blocks = []<EOL>def folded_context_visitor(expression):<EOL><INDENT>"""<STR_LIT>"""<EOL>if not isinstance(expression, LocalField):<EOL><INDENT>return expression<EOL><DEDENT>return GremlinFoldedLocalField(expression.field_name)<EOL><DEDENT>for block in folded_ir_blocks:<EOL><INDENT>new_block = block<EOL>if... | Convert Filter/Traverse blocks and LocalField expressions within @fold to Gremlin objects. | f12667:m3 |
def lower_folded_outputs(ir_blocks): | folds, remaining_ir_blocks = extract_folds_from_ir_blocks(ir_blocks)<EOL>if not remaining_ir_blocks:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT:{}>'.format(folds, remaining_ir_blocks, ir_blocks))<EOL><DEDENT>output_block = remaining_ir_blocks[-<NUM_LIT:1>]<EOL>if not isinstance(output_block, Construct... | Lower standard folded output fields into GremlinFoldedContextField objects. | f12667:m4 |
def __init__(self, fold_scope_location, folded_ir_blocks, field_type): | super(GremlinFoldedContextField, self).__init__(<EOL>fold_scope_location, folded_ir_blocks, field_type)<EOL>self.fold_scope_location = fold_scope_location<EOL>self.folded_ir_blocks = folded_ir_blocks<EOL>self.field_type = field_type<EOL>self.validate()<EOL> | Create a new GremlinFoldedContextField. | f12667:c0:m0 |
def validate(self): | if not isinstance(self.fold_scope_location, FoldScopeLocation):<EOL><INDENT>raise TypeError(u'<STR_LIT>'.format(<EOL>type(self.fold_scope_location), self.fold_scope_location))<EOL><DEDENT>allowed_block_types = (GremlinFoldedFilter, GremlinFoldedTraverse, Backtrack)<EOL>for block in self.folded_ir_blocks:<EOL><INDENT>if... | Validate that the GremlinFoldedContextField is correctly representable. | f12667:c0:m1 |
def to_match(self): | raise NotImplementedError()<EOL> | Must never be called. | f12667:c0:m2 |
def to_gremlin(self): | self.validate()<EOL>edge_direction, edge_name = self.fold_scope_location.get_first_folded_edge()<EOL>validate_safe_string(edge_name)<EOL>inverse_direction_table = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}<EOL>inverse_direction = inverse_direction_table[edge_direction]<EOL>base_location_name, _... | Return a unicode object with the Gremlin representation of this expression. | f12667:c0:m3 |
def to_gremlin(self): | self.validate()<EOL>return u'<STR_LIT>'.format(self.predicate.to_gremlin())<EOL> | Return a unicode object with the Gremlin representation of this block. | f12667:c1:m0 |
@classmethod<EOL><INDENT>def from_traverse(cls, traverse_block):<DEDENT> | if isinstance(traverse_block, Traverse):<EOL><INDENT>return cls(traverse_block.direction, traverse_block.edge_name)<EOL><DEDENT>else:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(type(traverse_block)))<EOL><DEDENT> | Create a GremlinFoldedTraverse block as a copy of the given Traverse block. | f12667:c2:m0 |
def to_gremlin(self): | self.validate()<EOL>template_data = {<EOL>'<STR_LIT>': self.direction,<EOL>'<STR_LIT>': self.edge_name,<EOL>'<STR_LIT>': '<STR_LIT>' if self.direction == '<STR_LIT>' else '<STR_LIT>'<EOL>}<EOL>return (u'<STR_LIT>'<EOL>u'<STR_LIT>'<EOL>.format(**template_data))<EOL> | Return a unicode object with the Gremlin representation of this block. | f12667:c2:m1 |
def get_local_object_gremlin_name(self): | return u'<STR_LIT>'<EOL> | Return the Gremlin name of the local object whose field is being produced. | f12667:c3:m0 |
def lower_ir(ir_blocks, query_metadata_table, type_equivalence_hints=None): | sanity_check_ir_blocks_from_frontend(ir_blocks, query_metadata_table)<EOL>ir_blocks = lower_context_field_existence(ir_blocks, query_metadata_table)<EOL>ir_blocks = optimize_boolean_expression_comparisons(ir_blocks)<EOL>if type_equivalence_hints:<EOL><INDENT>ir_blocks = lower_coerce_type_block_type_data(ir_blocks, type... | Lower the IR into an IR form that can be represented in Gremlin queries.
Args:
ir_blocks: list of IR blocks to lower into Gremlin-compatible form
query_metadata_table: QueryMetadataTable object containing all metadata collected during
query processing, including locati... | f12668:m0 |
def sanity_check_ir_blocks_from_frontend(ir_blocks, query_metadata_table): | if not ir_blocks:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'.format(ir_blocks))<EOL><DEDENT>_sanity_check_fold_scope_locations_are_unique(ir_blocks)<EOL>_sanity_check_no_nested_folds(ir_blocks)<EOL>_sanity_check_query_root_block(ir_blocks)<EOL>_sanity_check_output_source_follower_blocks(ir_blocks)<EOL>_sanity_check_... | Assert that IR blocks originating from the frontend do not have nonsensical structure.
Args:
ir_blocks: list of BasicBlocks representing the IR to sanity-check
Raises:
AssertionError, if the IR has unexpected structure. If the IR produced by the front-end
cannot be successfully and cor... | f12669:m0 |
def _sanity_check_registered_locations_parent_locations(query_metadata_table): | for location, location_info in query_metadata_table.registered_locations:<EOL><INDENT>if (location != query_metadata_table.root_location and<EOL>not query_metadata_table.root_location.is_revisited_at(location)):<EOL><INDENT>if location_info.parent_location is None:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<S... | Assert that all registered locations' parent locations are also registered. | f12669:m1 |
def _sanity_check_all_marked_locations_are_registered(ir_blocks, query_metadata_table): | <EOL>registered_locations = {<EOL>location<EOL>for location, _ in query_metadata_table.registered_locations<EOL>}<EOL>ir_encountered_locations = {<EOL>block.location<EOL>for block in ir_blocks<EOL>if isinstance(block, MarkLocation)<EOL>}<EOL>unregistered_locations = ir_encountered_locations - registered_locations<EOL>u... | Assert that all locations in MarkLocation blocks have registered and valid metadata. | f12669:m2 |
def _sanity_check_fold_scope_locations_are_unique(ir_blocks): | observed_locations = dict()<EOL>for block in ir_blocks:<EOL><INDENT>if isinstance(block, Fold):<EOL><INDENT>alternate = observed_locations.get(block.fold_scope_location, None)<EOL>if alternate is not None:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(alternate, block, ir_blocks))<EOL><DEDENT>ob... | Assert that every FoldScopeLocation that exists on a Fold block is unique. | f12669:m3 |
def _sanity_check_no_nested_folds(ir_blocks): | fold_seen = False<EOL>for block in ir_blocks:<EOL><INDENT>if isinstance(block, Fold):<EOL><INDENT>if fold_seen:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'.format(ir_blocks))<EOL><DEDENT>else:<EOL><INDENT>fold_seen = True<EOL><DEDENT><DEDENT>elif isinstance(block, Unfold):<EOL><INDENT>if not fold_seen:<EOL><INDENT>ra... | Assert that there are no nested Fold contexts, and that every Fold has a matching Unfold. | f12669:m4 |
def _sanity_check_query_root_block(ir_blocks): | if not isinstance(ir_blocks[<NUM_LIT:0>], QueryRoot):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'.format(ir_blocks))<EOL><DEDENT>for block in ir_blocks[<NUM_LIT:1>:]:<EOL><INDENT>if isinstance(block, QueryRoot):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'.format(ir_blocks))<EOL><DEDENT><DEDENT> | Assert that QueryRoot is always the first block, and only the first block. | f12669:m5 |
def _sanity_check_construct_result_block(ir_blocks): | if not isinstance(ir_blocks[-<NUM_LIT:1>], ConstructResult):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'.format(ir_blocks))<EOL><DEDENT>for block in ir_blocks[:-<NUM_LIT:1>]:<EOL><INDENT>if isinstance(block, ConstructResult):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT:{}>'.format(ir_blocks))<EOL><DE... | Assert that ConstructResult is always the last block, and only the last block. | f12669:m6 |
def _sanity_check_output_source_follower_blocks(ir_blocks): | seen_output_source = False<EOL>for block in ir_blocks:<EOL><INDENT>if isinstance(block, OutputSource):<EOL><INDENT>seen_output_source = True<EOL><DEDENT>elif seen_output_source:<EOL><INDENT>if isinstance(block, (Backtrack, Traverse, Recurse)):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'<EOL>u'<STR_LI... | Ensure there are no Traverse / Backtrack / Recurse blocks after an OutputSource block. | f12669:m7 |
def _sanity_check_block_pairwise_constraints(ir_blocks): | for first_block, second_block in pairwise(ir_blocks):<EOL><INDENT>if isinstance(first_block, MarkLocation) and isinstance(second_block, Filter):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'.format(ir_blocks))<EOL><DEDENT>if isinstance(first_block, MarkLocation) and isinstance(second_block, MarkLocation):<EOL><INDENT>r... | Assert that adjacent blocks obey all invariants. | f12669:m8 |
def _sanity_check_mark_location_preceding_optional_traverse(ir_blocks): | <EOL>_, new_ir_blocks = extract_folds_from_ir_blocks(ir_blocks)<EOL>for first_block, second_block in pairwise(new_ir_blocks):<EOL><INDENT>if isinstance(second_block, Traverse) and second_block.optional:<EOL><INDENT>if not isinstance(first_block, MarkLocation):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LI... | Assert that optional Traverse blocks are preceded by a MarkLocation. | f12669:m9 |
def _sanity_check_every_location_is_marked(ir_blocks): | <EOL>found_start_block = False<EOL>mark_location_blocks_count = <NUM_LIT:0><EOL>start_interval_types = (QueryRoot, Traverse, Recurse, Fold)<EOL>end_interval_types = (Backtrack, ConstructResult, Recurse, Traverse, Unfold)<EOL>for block in ir_blocks:<EOL><INDENT>if isinstance(block, end_interval_types) and found_start_bl... | Ensure that every new location is marked with a MarkLocation block. | f12669:m10 |
def _sanity_check_coerce_type_outside_of_fold(ir_blocks): | is_in_fold = False<EOL>for first_block, second_block in pairwise(ir_blocks):<EOL><INDENT>if isinstance(first_block, Fold):<EOL><INDENT>is_in_fold = True<EOL><DEDENT>if not is_in_fold and isinstance(first_block, CoerceType):<EOL><INDENT>if not isinstance(second_block, (MarkLocation, Filter)):<EOL><INDENT>raise Assertion... | Ensure that CoerceType not in a @fold are followed by a MarkLocation or Filter block. | f12669:m11 |
def merge_consecutive_filter_clauses(ir_blocks): | if not ir_blocks:<EOL><INDENT>return ir_blocks<EOL><DEDENT>new_ir_blocks = [ir_blocks[<NUM_LIT:0>]]<EOL>for block in ir_blocks[<NUM_LIT:1>:]:<EOL><INDENT>last_block = new_ir_blocks[-<NUM_LIT:1>]<EOL>if isinstance(last_block, Filter) and isinstance(block, Filter):<EOL><INDENT>new_ir_blocks[-<NUM_LIT:1>] = Filter(<EOL>Bi... | Merge consecutive Filter(x), Filter(y) blocks into Filter(x && y) block. | f12670:m0 |
def lower_context_field_existence(ir_blocks, query_metadata_table): | def regular_visitor_fn(expression):<EOL><INDENT>"""<STR_LIT>"""<EOL>if not isinstance(expression, ContextFieldExistence):<EOL><INDENT>return expression<EOL><DEDENT>location_type = query_metadata_table.get_location_info(expression.location).type<EOL>return BinaryComposition(<EOL>u'<STR_LIT>',<EOL>ContextField(expression... | Lower ContextFieldExistence expressions into lower-level expressions. | f12670:m1 |
def optimize_boolean_expression_comparisons(ir_blocks): | operator_inverses = {<EOL>u'<STR_LIT:=>': u'<STR_LIT>',<EOL>u'<STR_LIT>': u'<STR_LIT:=>',<EOL>}<EOL>def visitor_fn(expression):<EOL><INDENT>"""<STR_LIT>"""<EOL>if not isinstance(expression, BinaryComposition):<EOL><INDENT>return expression<EOL><DEDENT>left_is_binary_composition = isinstance(expression.left, BinaryCompo... | Optimize comparisons of a boolean binary comparison expression against a boolean literal.
Rewriting example:
BinaryComposition(
'=',
BinaryComposition('!=', something, NullLiteral)
False)
The above is rewritten into:
BinaryComposition('=', something, NullLit... | f12670:m2 |
def extract_folds_from_ir_blocks(ir_blocks): | folds = dict()<EOL>remaining_ir_blocks = []<EOL>current_folded_blocks = []<EOL>in_fold_location = None<EOL>for block in ir_blocks:<EOL><INDENT>if isinstance(block, Fold):<EOL><INDENT>if in_fold_location is not None:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT:{}>'.format(current_folded_blocks, remainin... | Extract all @fold data from the IR blocks, and cut the folded IR blocks out of the IR.
Args:
ir_blocks: list of IR blocks to extract fold data from
Returns:
tuple (folds, remaining_ir_blocks):
- folds: dict of FoldScopeLocation -> list of IR blocks corresponding to that @fold scope.
... | f12670:m3 |
def extract_optional_location_root_info(ir_blocks): | complex_optional_roots = []<EOL>location_to_optional_roots = dict()<EOL>in_optional_root_locations = []<EOL>encountered_traverse_within_optional = []<EOL>_, non_folded_ir_blocks = extract_folds_from_ir_blocks(ir_blocks)<EOL>preceding_location = None<EOL>for current_block in non_folded_ir_blocks:<EOL><INDENT>if len(in_o... | Construct a mapping from locations within @optional to their correspoding optional Traverse.
Args:
ir_blocks: list of IR blocks to extract optional data from
Returns:
tuple (complex_optional_roots, location_to_optional_roots):
complex_optional_roots: list of @optional locations (locati... | f12670:m4 |
def extract_simple_optional_location_info(<EOL>ir_blocks, complex_optional_roots, location_to_optional_roots): | <EOL>location_to_preceding_optional_root_iteritems = six.iteritems({<EOL>location: optional_root_locations_stack[-<NUM_LIT:1>]<EOL>for location, optional_root_locations_stack in six.iteritems(location_to_optional_roots)<EOL>})<EOL>simple_optional_root_to_inner_location = {<EOL>optional_root_location: inner_location<EOL... | Construct a map from simple optional locations to their inner location and traversed edge.
Args:
ir_blocks: list of IR blocks to extract optional data from
complex_optional_roots: list of @optional locations (location immmediately preceding
an @optional traverse) tha... | f12670:m5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.