signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def remove_end_optionals(ir_blocks): | new_ir_blocks = []<EOL>for block in ir_blocks:<EOL><INDENT>if not isinstance(block, EndOptional):<EOL><INDENT>new_ir_blocks.append(block)<EOL><DEDENT><DEDENT>return new_ir_blocks<EOL> | Return a list of IR blocks as a copy of the original, with EndOptional blocks removed. | f12670:m6 |
def validate(self): | super(OutputContextVertex, self).validate()<EOL>if self.location.field is not None:<EOL><INDENT>raise ValueError(u'<STR_LIT>'.format(self.location))<EOL><DEDENT> | Validate that the OutputContextVertex is correctly representable. | f12670:c0:m0 |
def to_match(self): | self.validate()<EOL>mark_name, field_name = self.location.get_location_name()<EOL>validate_safe_string(mark_name)<EOL>if field_name is not None:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(field_name, self.location))<EOL><DEDENT>return mark_name<EOL> | Return a unicode object with the MATCH representation of this expression. | f12670:c0:m1 |
def get_unique_directives(ast): | if not ast.directives:<EOL><INDENT>return dict()<EOL><DEDENT>result = dict()<EOL>for directive_obj in ast.directives:<EOL><INDENT>directive_name = directive_obj.name.value<EOL>if directive_name in ALLOWED_DUPLICATED_DIRECTIVES:<EOL><INDENT>pass <EOL><DEDENT>elif directive_name in result:<EOL><INDENT>raise GraphQLCompi... | Return a dict of directive name to directive object for the given AST node.
Any directives that are allowed to exist more than once on any AST node are ignored.
For any directives that can only exist up to once, we verify that they are not duplicated
raising GraphQLCompilationError in case we find them mor... | f12671:m0 |
def get_local_filter_directives(ast, current_schema_type, inner_vertex_fields): | result = []<EOL>if ast.directives: <EOL><INDENT>for directive_obj in ast.directives:<EOL><INDENT>if directive_obj.name.value == '<STR_LIT>':<EOL><INDENT>filtered_field_name = get_ast_field_name_or_none(ast)<EOL>if is_filter_with_outer_scope_vertex_field_operator(directive_obj):<EOL><INDENT>if not is_vertex_field_type(... | Get all filter directives that apply to the current field.
This helper abstracts away the fact that some vertex field filtering operators apply on the
inner scope (the scope of the inner vertex field on which they are applied), whereas some apply
on the outer scope (the scope that contains the inner vertex... | f12671:m1 |
def validate_property_directives(directives): | for directive_name in six.iterkeys(directives):<EOL><INDENT>if directive_name in VERTEX_ONLY_DIRECTIVES:<EOL><INDENT>raise GraphQLCompilationError(<EOL>u'<STR_LIT>'.format(directive_name))<EOL><DEDENT><DEDENT> | Validate the directives that appear at a property field. | f12671:m2 |
def validate_vertex_directives(directives): | for directive_name in six.iterkeys(directives):<EOL><INDENT>if directive_name in PROPERTY_ONLY_DIRECTIVES:<EOL><INDENT>raise GraphQLCompilationError(<EOL>u'<STR_LIT>'.format(directive_name))<EOL><DEDENT><DEDENT> | Validate the directives that appear at a vertex field. | f12671:m3 |
def validate_root_vertex_directives(root_ast): | directives_present_at_root = set()<EOL>for directive_obj in root_ast.directives:<EOL><INDENT>directive_name = directive_obj.name.value<EOL>if is_filter_with_outer_scope_vertex_field_operator(directive_obj):<EOL><INDENT>raise GraphQLCompilationError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(directive_obj))<EOL><DEDENT>direct... | Validate the directives that appear at the root vertex field. | f12671:m4 |
def validate_vertex_field_directive_interactions(parent_location, vertex_field_name, directives): | fold_directive = directives.get('<STR_LIT>', None)<EOL>optional_directive = directives.get('<STR_LIT>', None)<EOL>output_source_directive = directives.get('<STR_LIT>', None)<EOL>recurse_directive = directives.get('<STR_LIT>', None)<EOL>if fold_directive and optional_directive:<EOL><INDENT>raise GraphQLCompilationError(... | Ensure that the specified vertex field directives are not mutually disallowed. | f12671:m5 |
def validate_vertex_field_directive_in_context(parent_location, vertex_field_name,<EOL>directives, context): | fold_directive = directives.get('<STR_LIT>', None)<EOL>optional_directive = directives.get('<STR_LIT>', None)<EOL>recurse_directive = directives.get('<STR_LIT>', None)<EOL>output_source_directive = directives.get('<STR_LIT>', None)<EOL>fold_context = '<STR_LIT>' in context<EOL>optional_context = '<STR_LIT>' in context<... | Ensure that the specified vertex field directives are allowed in the current context. | f12671:m6 |
def compile_graphql_to_match(schema, graphql_string, type_equivalence_hints=None): | lowering_func = ir_lowering_match.lower_ir<EOL>query_emitter_func = emit_match.emit_code_from_ir<EOL>return _compile_graphql_generic(<EOL>MATCH_LANGUAGE, lowering_func, query_emitter_func,<EOL>schema, graphql_string, type_equivalence_hints, None)<EOL> | Compile the GraphQL input using the schema into a MATCH query and associated metadata.
Args:
schema: GraphQL schema object describing the schema of the graph to be queried
graphql_string: the GraphQL query to compile to MATCH, as a string
type_equivalence_hints: optional dict of GraphQL int... | f12672:m0 |
def compile_graphql_to_gremlin(schema, graphql_string, type_equivalence_hints=None): | lowering_func = ir_lowering_gremlin.lower_ir<EOL>query_emitter_func = emit_gremlin.emit_code_from_ir<EOL>return _compile_graphql_generic(<EOL>GREMLIN_LANGUAGE, lowering_func, query_emitter_func,<EOL>schema, graphql_string, type_equivalence_hints, None)<EOL> | Compile the GraphQL input using the schema into a Gremlin query and associated metadata.
Args:
schema: GraphQL schema object describing the schema of the graph to be queried
graphql_string: the GraphQL query to compile to Gremlin, as a string
type_equivalence_hints: optional dict of GraphQL... | f12672:m1 |
def compile_graphql_to_sql(schema, graphql_string, compiler_metadata, type_equivalence_hints=None): | lowering_func = ir_lowering_sql.lower_ir<EOL>query_emitter_func = emit_sql.emit_code_from_ir<EOL>return _compile_graphql_generic(<EOL>SQL_LANGUAGE, lowering_func, query_emitter_func,<EOL>schema, graphql_string, type_equivalence_hints, compiler_metadata)<EOL> | Compile the GraphQL input using the schema into a SQL query and associated metadata.
Args:
schema: GraphQL schema object describing the schema of the graph to be queried
graphql_string: the GraphQL query to compile to SQL, as a string
compiler_metadata: SQLAlchemy metadata containing tables... | f12672:m2 |
def _compile_graphql_generic(language, lowering_func, query_emitter_func,<EOL>schema, graphql_string, type_equivalence_hints, compiler_metadata): | ir_and_metadata = graphql_to_ir(<EOL>schema, graphql_string, type_equivalence_hints=type_equivalence_hints)<EOL>lowered_ir_blocks = lowering_func(<EOL>ir_and_metadata.ir_blocks, ir_and_metadata.query_metadata_table,<EOL>type_equivalence_hints=type_equivalence_hints)<EOL>query = query_emitter_func(lowered_ir_blocks, com... | Compile the GraphQL input, lowering and emitting the query using the given functions.
Args:
language: string indicating the target language to compile to.
lowering_func: Function to lower the compiler IR into a compatible form for the target
language backend.
query_em... | f12672:m3 |
def _per_location_tuple_to_step(ir_tuple): | root_block = ir_tuple[<NUM_LIT:0>]<EOL>if not isinstance(root_block, root_block_types):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(root_block, ir_tuple))<EOL><DEDENT>coerce_type_block = None<EOL>where_block = None<EOL>as_block = None<EOL>for block in ir_tuple[<NUM_LIT:1>:]:<EOL><INDENT>if isi... | Construct a MatchStep from a tuple of its constituent blocks. | f12673:m0 |
def _split_ir_into_match_steps(pruned_ir_blocks): | output = []<EOL>current_tuple = None<EOL>for block in pruned_ir_blocks:<EOL><INDENT>if isinstance(block, OutputSource):<EOL><INDENT>continue<EOL><DEDENT>elif isinstance(block, root_block_types):<EOL><INDENT>if current_tuple is not None:<EOL><INDENT>output.append(current_tuple)<EOL><DEDENT>current_tuple = (block,)<EOL><... | Split a list of IR blocks into per-location MATCH steps.
Args:
pruned_ir_blocks: list of IR basic block objects that have gone through a lowering step.
Returns:
list of MatchStep namedtuples, each of which contains all basic blocks that correspond
to a single MATCH step. | f12673:m1 |
def _split_match_steps_into_match_traversals(match_steps): | output = []<EOL>current_list = None<EOL>for step in match_steps:<EOL><INDENT>if isinstance(step.root_block, QueryRoot):<EOL><INDENT>if current_list is not None:<EOL><INDENT>output.append(current_list)<EOL><DEDENT>current_list = [step]<EOL><DEDENT>else:<EOL><INDENT>current_list.append(step)<EOL><DEDENT><DEDENT>if curren... | Split a list of MatchSteps into multiple lists, each denoting a single MATCH traversal. | f12673:m2 |
def _extract_global_operations(ir_blocks_except_output_and_folds): | global_operation_blocks = []<EOL>remaining_ir_blocks = []<EOL>in_global_operations_scope = False<EOL>for block in ir_blocks_except_output_and_folds:<EOL><INDENT>if isinstance(block, (ConstructResult, Fold, Unfold)):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'<EOL>.format(type(block).__name__, ir_bloc... | Extract all global operation blocks (all blocks following GlobalOperationsStart).
Args:
ir_blocks_except_output_and_folds: list of IR blocks (excluding ConstructResult and all
fold blocks), to extract global operations from
Returns:
tuple (global_oper... | f12673:m3 |
def convert_to_match_query(ir_blocks): | output_block = ir_blocks[-<NUM_LIT:1>]<EOL>if not isinstance(output_block, ConstructResult):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(output_block, ir_blocks))<EOL><DEDENT>ir_except_output = ir_blocks[:-<NUM_LIT:1>]<EOL>folds, ir_except_output_and_folds = extract_folds_from_ir_blocks(ir_exc... | Convert the list of IR blocks into a MatchQuery object, for easier manipulation. | f12673:m4 |
def get_only_element_from_collection(one_element_collection): | if len(one_element_collection) != <NUM_LIT:1>:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>.format(one_element_collection))<EOL><DEDENT>return funcy.first(one_element_collection)<EOL> | Assert that the collection has exactly one element, then return that element. | f12675:m0 |
def get_ast_field_name(ast): | replacements = {<EOL>TYPENAME_META_FIELD_NAME: '<STR_LIT>'<EOL>}<EOL>base_field_name = ast.name.value<EOL>normalized_name = replacements.get(base_field_name, base_field_name)<EOL>return normalized_name<EOL> | Return the normalized field name for the given AST node. | f12675:m1 |
def get_ast_field_name_or_none(ast): | if isinstance(ast, InlineFragment):<EOL><INDENT>return None<EOL><DEDENT>return get_ast_field_name(ast)<EOL> | Return the field name for the AST node, or None if the AST is an InlineFragment. | f12675:m2 |
def get_field_type_from_schema(schema_type, field_name): | if field_name == '<STR_LIT>':<EOL><INDENT>return GraphQLString<EOL><DEDENT>else:<EOL><INDENT>if field_name not in schema_type.fields:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT:{}>'.format(field_name, schema_type))<EOL><DEDENT>return schema_type.fields[field_name].type<EOL><DEDENT> | Return the type of the field in the given type, accounting for field name normalization. | f12675:m3 |
def get_vertex_field_type(current_schema_type, vertex_field_name): | <EOL>if not is_vertex_field_name(vertex_field_name):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(current_schema_type, vertex_field_name))<EOL><DEDENT>raw_field_type = get_field_type_from_schema(current_schema_type, vertex_field_name)<EOL>if not isinstance(strip_non_null_from_type(raw_field_typ... | Return the type of the vertex within the specified vertex field name of the given type. | f12675:m4 |
def strip_non_null_from_type(graphql_type): | while isinstance(graphql_type, GraphQLNonNull):<EOL><INDENT>graphql_type = graphql_type.of_type<EOL><DEDENT>return graphql_type<EOL> | Return the GraphQL type stripped of its GraphQLNonNull annotations. | f12675:m5 |
def get_edge_direction_and_name(vertex_field_name): | edge_direction = None<EOL>edge_name = None<EOL>if vertex_field_name.startswith(OUTBOUND_EDGE_FIELD_PREFIX):<EOL><INDENT>edge_direction = OUTBOUND_EDGE_DIRECTION<EOL>edge_name = vertex_field_name[len(OUTBOUND_EDGE_FIELD_PREFIX):]<EOL><DEDENT>elif vertex_field_name.startswith(INBOUND_EDGE_FIELD_PREFIX):<EOL><INDENT>edge_... | Get the edge direction and name from a non-root vertex field name. | f12675:m6 |
def is_vertex_field_name(field_name): | return (<EOL>field_name.startswith(OUTBOUND_EDGE_FIELD_PREFIX) or<EOL>field_name.startswith(INBOUND_EDGE_FIELD_PREFIX)<EOL>)<EOL> | Return True if the field's name indicates it is a non-root vertex field. | f12675:m7 |
def is_vertex_field_type(graphql_type): | <EOL>underlying_type = strip_non_null_from_type(graphql_type)<EOL>return isinstance(underlying_type, (GraphQLInterfaceType, GraphQLObjectType, GraphQLUnionType))<EOL> | Return True if the argument is a vertex field type, and False otherwise. | f12675:m8 |
def is_graphql_type(graphql_type): | <EOL>return is_type(graphql_type)<EOL> | Return True if the argument is a GraphQL type object, and False otherwise. | f12675:m9 |
def ensure_unicode_string(value): | if not isinstance(value, six.string_types):<EOL><INDENT>raise TypeError(u'<STR_LIT>'.format(value))<EOL><DEDENT>return six.text_type(value)<EOL> | Ensure the value is a string, and return it as unicode. | f12675:m10 |
def get_uniquely_named_objects_by_name(object_list): | if not object_list:<EOL><INDENT>return dict()<EOL><DEDENT>result = dict()<EOL>for obj in object_list:<EOL><INDENT>name = obj.name.value<EOL>if name in result:<EOL><INDENT>raise GraphQLCompilationError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(name, object_list))<EOL><DEDENT>result[name] = obj<EOL><DEDENT>return result<EOL> | Return dict of name -> object pairs from a list of objects with unique names.
Args:
object_list: list of objects, each X of which has a unique name accessible as X.name.value
Returns:
dict, { X.name.value: X for x in object_list }
If the list is empty or None, returns an empty dict. | f12675:m11 |
def safe_quoted_string(value): | validate_safe_string(value)<EOL>return u'<STR_LIT>'.format(value)<EOL> | Return the provided string, surrounded by single quotes. Unsafe strings cause exceptions. | f12675:m12 |
def validate_safe_string(value): | <EOL>legal_strings_with_special_chars = frozenset({'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT:%>'})<EOL>if not isinstance(value, six.string_types):<EOL><INDENT>raise TypeError(u'<STR_LIT>'.format(<EOL>type(value).__name__, value))<EOL><DEDENT>if not value:<EOL><INDENT>raise GraphQLCompilationError(u'<STR_LIT>')<E... | Ensure the provided string does not have illegal characters. | f12675:m13 |
def validate_output_name(value): | internal_name_prefix = u'<STR_LIT>'<EOL>if value.startswith(internal_name_prefix):<EOL><INDENT>raise GraphQLCompilationError(<EOL>u'<STR_LIT>')<EOL><DEDENT> | Ensure that the provided string is valid for use as an output name. | f12675:m14 |
def validate_edge_direction(edge_direction): | if not isinstance(edge_direction, six.string_types):<EOL><INDENT>raise TypeError(u'<STR_LIT>'.format(<EOL>type(edge_direction), edge_direction))<EOL><DEDENT>if edge_direction not in ALLOWED_EDGE_DIRECTIONS:<EOL><INDENT>raise ValueError(u'<STR_LIT>'.format(edge_direction))<EOL><DEDENT> | Ensure the provided edge direction is either "in" or "out". | f12675:m15 |
def validate_marked_location(location): | if not isinstance(location, (Location, FoldScopeLocation)):<EOL><INDENT>raise TypeError(u'<STR_LIT>'.format(<EOL>type(location).__name__, location))<EOL><DEDENT>if location.field is not None:<EOL><INDENT>raise GraphQLCompilationError(u'<STR_LIT>'.format(location))<EOL><DEDENT> | Validate that a Location object is safe for marking, and not at a field. | f12675:m16 |
def _create_fold_path_component(edge_direction, edge_name): | return ((edge_direction, edge_name),)<EOL> | Return a tuple representing a fold_path component of a FoldScopeLocation. | f12675:m17 |
def invert_dict(invertible_dict): | inverted = {}<EOL>for k, v in six.iteritems(invertible_dict):<EOL><INDENT>if not isinstance(v, Hashable):<EOL><INDENT>raise TypeError(u'<STR_LIT>'.format(<EOL>k, type(v).__name__))<EOL><DEDENT>if v in inverted:<EOL><INDENT>raise TypeError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(<EOL>inverted[v], k))<EOL><DEDENT>inverted[v... | Invert a dict. A dict is invertible if values are unique and hashable. | f12675:m18 |
def is_variable_argument(argument): | return argument.startswith('<STR_LIT:$>')<EOL> | Return True if the directive argument is a runtime variable, and False otherwise. | f12675:m19 |
def is_tag_argument(argument): | return argument.startswith('<STR_LIT:%>')<EOL> | Return True if the directive argument is a tagged value, and False otherwise. | f12675:m20 |
def get_directive_argument_name(argument): | return argument[<NUM_LIT:1>:]<EOL> | Return the name of a variable or tag argument without the $ or %. | f12675:m21 |
@abstractmethod<EOL><INDENT>def navigate_to_field(self, field):<DEDENT> | raise NotImplementedError()<EOL> | Return a new BaseLocation object at the specified field of the current BaseLocation. | f12675:c0:m0 |
@abstractmethod<EOL><INDENT>def navigate_to_subpath(self, child):<DEDENT> | raise NotImplementedError()<EOL> | Return a new BaseLocation after a traversal to the specified child location. | f12675:c0:m1 |
@abstractmethod<EOL><INDENT>def get_location_name(self):<DEDENT> | raise NotImplementedError()<EOL> | Return a tuple of a unique name of the location, and the current field name (or None). | f12675:c0:m2 |
@abstractmethod<EOL><INDENT>def _check_if_object_of_same_type_is_smaller(self, other):<DEDENT> | raise NotImplementedError()<EOL> | Return True if the other object is smaller than self in the total ordering. | f12675:c0:m3 |
@abstractmethod<EOL><INDENT>def __eq__(self, other):<DEDENT> | raise NotImplementedError()<EOL> | Return True if the BaseLocations are equal, and False otherwise. | f12675:c0:m4 |
def __lt__(self, other): | if isinstance(self, Location) and isinstance(other, Location):<EOL><INDENT>return self._check_if_object_of_same_type_is_smaller(other)<EOL><DEDENT>elif isinstance(self, FoldScopeLocation) and isinstance(other, FoldScopeLocation):<EOL><INDENT>return self._check_if_object_of_same_type_is_smaller(other)<EOL><DEDENT>elif i... | Return True if the other object is smaller than self in the total ordering. | f12675:c0:m5 |
def __init__(self, query_path, field=None, visit_counter=<NUM_LIT:1>): | if not isinstance(query_path, tuple):<EOL><INDENT>raise TypeError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(type(query_path).__name__, query_path))<EOL><DEDENT>if field and not isinstance(field, six.string_types):<EOL><INDENT>raise TypeError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(type(field).__name__, field))<EOL><DEDENT>self... | Create a new Location object.
Used to uniquely identify locations in the graph traversal, with three components.
- The 'query_path' is a tuple containing the in-order nested set of vertex fields where
the Location is.
- The 'field' is a string set to the name of a property... | f12675:c1:m0 |
def navigate_to_field(self, field): | if self.field:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'.format(self))<EOL><DEDENT>return Location(self.query_path, field=field, visit_counter=self.visit_counter)<EOL> | Return a new Location object at the specified field of the current Location's vertex. | f12675:c1:m1 |
def at_vertex(self): | if not self.field:<EOL><INDENT>return self<EOL><DEDENT>return Location(self.query_path, field=None, visit_counter=self.visit_counter)<EOL> | Get the Location ignoring its field component. | f12675:c1:m2 |
def navigate_to_subpath(self, child): | if not isinstance(child, six.string_types):<EOL><INDENT>raise TypeError(u'<STR_LIT>'.format(child))<EOL><DEDENT>if self.field:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'.format(self))<EOL><DEDENT>return Location(self.query_path + (child,))<EOL> | Return a new Location object at a child vertex of the current Location's vertex. | f12675:c1:m3 |
def navigate_to_fold(self, folded_child): | if not isinstance(folded_child, six.string_types):<EOL><INDENT>raise TypeError(u'<STR_LIT>'.format(folded_child))<EOL><DEDENT>if self.field:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT:{}>'.format(self))<EOL><DEDENT>edge_direction, edge_name = get_edge_direction_and_name(folded_child)<EOL>fold_path = _... | Return a new FoldScopeLocation for the folded child vertex of the current Location. | f12675:c1:m4 |
def revisit(self): | if self.field:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'.format(self))<EOL><DEDENT>return Location(self.query_path, field=None, visit_counter=(self.visit_counter + <NUM_LIT:1>))<EOL> | Return a new Location object with an incremented 'visit_counter'. | f12675:c1:m5 |
def get_location_name(self): | mark_name = u'<STR_LIT>'.join(self.query_path) + u'<STR_LIT>' + six.text_type(self.visit_counter)<EOL>return (mark_name, self.field)<EOL> | Return a tuple of a unique name of the Location, and the current field name (or None). | f12675:c1:m6 |
def is_revisited_at(self, other_location): | <EOL>return (isinstance(other_location, Location) and<EOL>self.query_path == other_location.query_path and<EOL>self.visit_counter < other_location.visit_counter)<EOL> | Return True if other_location is a revisit of this location, and False otherwise. | f12675:c1:m7 |
def __str__(self): | return u'<STR_LIT>'.format(self.query_path, self.field, self.visit_counter)<EOL> | Return a human-readable str representation of the Location object. | f12675:c1:m8 |
def __repr__(self): | return self.__str__()<EOL> | Return a human-readable str representation of the Location object. | f12675:c1:m9 |
def __eq__(self, other): | return (type(self) == type(other) and<EOL>self.query_path == other.query_path and<EOL>self.field == other.field and<EOL>self.visit_counter == other.visit_counter)<EOL> | Return True if the Locations are equal, and False otherwise. | f12675:c1:m10 |
def __ne__(self, other): | return not self.__eq__(other)<EOL> | Check another object for non-equality against this one. | f12675:c1:m11 |
def _check_if_object_of_same_type_is_smaller(self, other): | if not isinstance(other, Location):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>.format(type(other).__name__, other))<EOL><DEDENT>if len(self.query_path) != len(other.query_path):<EOL><INDENT>return len(self.query_path) < len(other.query_path)<EOL><DEDENT>if self.query_path != other.query_path:<EOL><INDENT>return... | Return True if the other object is smaller than self in the total ordering. | f12675:c1:m12 |
def __hash__(self): | return hash(self.query_path) ^ hash(self.field) ^ hash(self.visit_counter)<EOL> | Return the object's hash value. | f12675:c1:m13 |
def __init__(self, base_location, fold_path, field=None): | if not isinstance(base_location, Location):<EOL><INDENT>raise TypeError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(type(base_location), base_location))<EOL><DEDENT>if base_location.field:<EOL><INDENT>raise ValueError(u'<STR_LIT>'<EOL>u'<STR_LIT:{}>'.format(base_location))<EOL><DEDENT>if not isinstance(fold_path, tuple) or le... | Create a new FoldScopeLocation object. Used to represent the locations of @fold scopes.
Args:
base_location: Location object defining where the @fold scope is rooted. In other words,
the location of the tightest scope that fully contains the @fold scope.
fold_... | f12675:c2:m0 |
def get_location_name(self): | <EOL>first_folded_edge_direction, first_folded_edge_name = self.get_first_folded_edge()<EOL>unique_name = u'<STR_LIT>'.join((<EOL>self.base_location.get_location_name()[<NUM_LIT:0>],<EOL>u'<STR_LIT>',<EOL>first_folded_edge_direction,<EOL>u'<STR_LIT:_>',<EOL>first_folded_edge_name<EOL>))<EOL>return (unique_name, self.fi... | Return a tuple of a unique name of the location, and the current field name (or None). | f12675:c2:m1 |
def get_first_folded_edge(self): | <EOL>first_folded_edge_direction, first_folded_edge_name = self.fold_path[<NUM_LIT:0>]<EOL>return first_folded_edge_direction, first_folded_edge_name<EOL> | Return a tuple representing the first folded edge within the fold scope. | f12675:c2:m2 |
def at_vertex(self): | if not self.field:<EOL><INDENT>return self<EOL><DEDENT>return FoldScopeLocation(self.base_location, self.fold_path, field=None)<EOL> | Get the FoldScopeLocation ignoring its field component. | f12675:c2:m3 |
def navigate_to_field(self, field): | if self.field:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'.format(self))<EOL><DEDENT>return FoldScopeLocation(self.base_location, self.fold_path, field=field)<EOL> | Return a new location object at the specified field of the current location. | f12675:c2:m4 |
def navigate_to_subpath(self, child): | if not isinstance(child, six.string_types):<EOL><INDENT>raise TypeError(u'<STR_LIT>'.format(child))<EOL><DEDENT>if self.field:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'.format(self))<EOL><DEDENT>edge_direction, edge_name = get_edge_direction_and_name(child)<EOL>new_fold_path = self.fold_path + _create_fold_path_com... | Return a new location after a traversal to the specified child location. | f12675:c2:m5 |
def __str__(self): | return u'<STR_LIT>'.format(<EOL>self.base_location, self.fold_path, self.field)<EOL> | Return a human-readable str representation of the FoldScopeLocation object. | f12675:c2:m6 |
def __repr__(self): | return self.__str__()<EOL> | Return a human-readable str representation of the FoldScopeLocation object. | f12675:c2:m7 |
def __eq__(self, other): | return (type(self) == type(other) and<EOL>self.base_location == other.base_location and<EOL>self.fold_path == other.fold_path and<EOL>self.field == other.field)<EOL> | Return True if the FoldScopeLocations are equal, and False otherwise. | f12675:c2:m8 |
def __ne__(self, other): | return not self.__eq__(other)<EOL> | Check another object for non-equality against this one. | f12675:c2:m9 |
def __hash__(self): | return hash(self.base_location) ^ hash(self.fold_path) ^ hash(self.field)<EOL> | Return the object's hash value. | f12675:c2:m10 |
def _check_if_object_of_same_type_is_smaller(self, other): | if not isinstance(other, FoldScopeLocation):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>.format(type(other).__name__, other))<EOL><DEDENT>if self.base_location != other.base_location:<EOL><INDENT>return self.base_location < other.base_location<EOL><DEDENT>if len(self.fold_path) != len(other.fold_path):<EOL><INDE... | Return True if the other object is smaller than self in the total ordering. | f12675:c2:m11 |
def rewrite_binary_composition_inside_ternary_conditional(ir_blocks): | def visitor_fn(expression):<EOL><INDENT>"""<STR_LIT>"""<EOL>if not isinstance(expression, TernaryConditional):<EOL><INDENT>return expression<EOL><DEDENT>if_true = expression.if_true<EOL>if_false = expression.if_false<EOL>true_branch_rewriting_necessary = isinstance(if_true, BinaryComposition)<EOL>false_branch_rewriting... | Rewrite BinaryConditional expressions in the true/false values of TernaryConditionals. | f12676:m0 |
def lower_has_substring_binary_compositions(ir_blocks): | def visitor_fn(expression):<EOL><INDENT>"""<STR_LIT>"""<EOL>if not isinstance(expression, BinaryComposition) or expression.operator != u'<STR_LIT>':<EOL><INDENT>return expression<EOL><DEDENT>return BinaryComposition(<EOL>u'<STR_LIT>',<EOL>expression.left,<EOL>BinaryComposition(<EOL>u'<STR_LIT:+>',<EOL>Literal('<STR_LIT... | Lower Filter blocks that use the "has_substring" operation into MATCH-representable form. | f12676:m1 |
def truncate_repeated_single_step_traversals(match_query): | <EOL>new_match_traversals = []<EOL>visited_locations = set()<EOL>for current_match_traversal in match_query.match_traversals:<EOL><INDENT>ignore_traversal = False<EOL>if len(current_match_traversal) == <NUM_LIT:1>:<EOL><INDENT>single_step = current_match_traversal[<NUM_LIT:0>]<EOL>if single_step.as_block is None:<EOL><... | Truncate one-step traversals that overlap a previous traversal location. | f12676:m2 |
def lower_backtrack_blocks(match_query, location_types): | <EOL>new_match_traversals = []<EOL>location_translations = dict()<EOL>for current_match_traversal in match_query.match_traversals:<EOL><INDENT>new_traversal = []<EOL>for step in current_match_traversal:<EOL><INDENT>if not isinstance(step.root_block, Backtrack):<EOL><INDENT>new_traversal.append(step)<EOL><DEDENT>else:<E... | Lower Backtrack blocks into (QueryRoot, MarkLocation) pairs of blocks. | f12676:m3 |
def _flatten_location_translations(location_translations): | sources_to_process = set(six.iterkeys(location_translations))<EOL>def _update_translation(source):<EOL><INDENT>"""<STR_LIT>"""<EOL>destination = location_translations[source]<EOL>if destination not in location_translations:<EOL><INDENT>return destination<EOL><DEDENT>else:<EOL><INDENT>sources_to_process.discard(destinat... | If location A translates to B, and B to C, then make A translate directly to C.
Args:
location_translations: dict of Location -> Location, where the key translates to the value.
Mutated in place for efficiency and simplicity of implementation. | f12676:m4 |
def _translate_equivalent_locations(match_query, location_translations): | new_match_traversals = []<EOL>def visitor_fn(expression):<EOL><INDENT>"""<STR_LIT>"""<EOL>if isinstance(expression, (ContextField, GlobalContextField)):<EOL><INDENT>old_location = expression.location.at_vertex()<EOL>new_location = location_translations.get(old_location, old_location)<EOL>if expression.location.field is... | Translate Location objects into their equivalent locations, based on the given dict. | f12676:m5 |
def lower_folded_coerce_types_into_filter_blocks(folded_ir_blocks): | new_folded_ir_blocks = []<EOL>for block in folded_ir_blocks:<EOL><INDENT>if isinstance(block, CoerceType):<EOL><INDENT>new_block = convert_coerce_type_to_instanceof_filter(block)<EOL><DEDENT>else:<EOL><INDENT>new_block = block<EOL><DEDENT>new_folded_ir_blocks.append(new_block)<EOL><DEDENT>return new_folded_ir_blocks<EO... | Lower CoerceType blocks into "INSTANCEOF" Filter blocks. Indended for folded IR blocks. | f12676:m6 |
def remove_backtrack_blocks_from_fold(folded_ir_blocks): | new_folded_ir_blocks = []<EOL>for block in folded_ir_blocks:<EOL><INDENT>if not isinstance(block, Backtrack):<EOL><INDENT>new_folded_ir_blocks.append(block)<EOL><DEDENT><DEDENT>return new_folded_ir_blocks<EOL> | Return a list of IR blocks with all Backtrack blocks removed. | f12676:m7 |
def truncate_repeated_single_step_traversals_in_sub_queries(compound_match_query): | lowered_match_queries = []<EOL>for match_query in compound_match_query.match_queries:<EOL><INDENT>new_match_query = truncate_repeated_single_step_traversals(match_query)<EOL>lowered_match_queries.append(new_match_query)<EOL><DEDENT>return compound_match_query._replace(match_queries=lowered_match_queries)<EOL> | For each sub-query, remove one-step traversals that overlap a previous traversal location. | f12676:m8 |
def lower_ir(ir_blocks, query_metadata_table, type_equivalence_hints=None): | sanity_check_ir_blocks_from_frontend(ir_blocks, query_metadata_table)<EOL>location_types = {<EOL>location: location_info.type<EOL>for location, location_info in query_metadata_table.registered_locations<EOL>}<EOL>coerced_locations = {<EOL>location<EOL>for location, location_info in query_metadata_table.registered_locat... | Lower the IR into an IR form that can be represented in MATCH queries.
Args:
ir_blocks: list of IR blocks to lower into MATCH-compatible form
query_metadata_table: QueryMetadataTable object containing all metadata collected during
query processing, including location m... | f12677:m0 |
def _expression_list_to_conjunction(expression_list): | if not isinstance(expression_list, list):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT:{}>'.format(type(expression_list).__name__, expression_list))<EOL><DEDENT>if len(expression_list) == <NUM_LIT:0>:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'<EOL>u'<STR_LIT:{}>'.format(expression_li... | Return an Expression that is the `&&` of all the expressions in the given list. | f12678:m0 |
def _extract_conjuction_elements_from_expression(expression): | if isinstance(expression, BinaryComposition) and expression.operator == u'<STR_LIT>':<EOL><INDENT>for element in _extract_conjuction_elements_from_expression(expression.left):<EOL><INDENT>yield element<EOL><DEDENT>for element in _extract_conjuction_elements_from_expression(expression.right):<EOL><INDENT>yield element<E... | Return a generator for expressions that are connected by `&&`s in the given expression. | f12678:m1 |
def _construct_field_operator_expression_dict(expression_list): | between_operators = (u'<STR_LIT>', u'<STR_LIT>')<EOL>inverse_operator = {u'<STR_LIT>': u'<STR_LIT>', u'<STR_LIT>': u'<STR_LIT>'}<EOL>local_field_to_expressions = {}<EOL>remaining_expression_list = deque([])<EOL>for expression in expression_list:<EOL><INDENT>if all((<EOL>isinstance(expression, BinaryComposition),<EOL>ex... | Construct a mapping from local fields to specified operators, and corresponding expressions.
Args:
expression_list: list of expressions to analyze
Returns:
local_field_to_expressions:
dict mapping local field names to "operator -> list of BinaryComposition" dictionaries,
... | f12678:m2 |
def _lower_expressions_to_between(base_expression): | expression_list = list(_extract_conjuction_elements_from_expression(base_expression))<EOL>if len(expression_list) == <NUM_LIT:0>:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT:{}>'.format(expression_list, base_expression))<EOL><DEDENT>elif len(expression_list) == <NUM_LIT:1>:<EOL><INDENT>return base_expr... | Return a new expression, with any eligible comparisons lowered to `between` clauses. | f12678:m3 |
def lower_comparisons_to_between(match_query): | new_match_traversals = []<EOL>for current_match_traversal in match_query.match_traversals:<EOL><INDENT>new_traversal = []<EOL>for step in current_match_traversal:<EOL><INDENT>if step.where_block:<EOL><INDENT>expression = step.where_block.predicate<EOL>new_where_block = Filter(_lower_expressions_to_between(expression))<... | Return a new MatchQuery, with all eligible comparison filters lowered to between clauses. | f12678:m4 |
def _prune_traverse_using_omitted_locations(match_traversal, omitted_locations,<EOL>complex_optional_roots, location_to_optional_roots): | new_match_traversal = []<EOL>for step in match_traversal:<EOL><INDENT>new_step = step<EOL>if isinstance(step.root_block, Traverse) and step.root_block.optional:<EOL><INDENT>current_location = step.as_block.location<EOL>optional_root_locations_stack = location_to_optional_roots.get(current_location, None)<EOL>optional_r... | Return a prefix of the given traverse, excluding any blocks after an omitted optional.
Given a subset (omitted_locations) of complex_optional_roots, return a new match traversal
removing all MatchStep objects that are within any omitted location.
Args:
match_traversal: list of MatchStep objects to... | f12679:m0 |
def convert_optional_traversals_to_compound_match_query(<EOL>match_query, complex_optional_roots, location_to_optional_roots): | tree = construct_optional_traversal_tree(<EOL>complex_optional_roots, location_to_optional_roots)<EOL>rooted_optional_root_location_subsets = tree.get_all_rooted_subtrees_as_lists()<EOL>omitted_location_subsets = [<EOL>set(complex_optional_roots) - set(subset)<EOL>for subset in rooted_optional_root_location_subsets<EOL... | Return 2^n distinct MatchQuery objects in a CompoundMatchQuery.
Given a MatchQuery containing `n` optional traverses that expand vertex fields,
construct `2^n` different MatchQuery objects:
one for each possible subset of optional edges that can be followed.
For each edge `e` in a subset of optional ed... | f12679:m1 |
def _get_present_locations(match_traversals): | present_locations = set()<EOL>present_non_optional_locations = set()<EOL>for match_traversal in match_traversals:<EOL><INDENT>for step in match_traversal:<EOL><INDENT>if step.as_block is not None:<EOL><INDENT>location_name, _ = step.as_block.location.get_location_name()<EOL>present_locations.add(location_name)<EOL>if i... | Return the set of locations and non-optional locations present in the given match traversals.
When enumerating the possibilities for optional traversals,
the resulting match traversals may have sections of the query omitted.
These locations will not be included in the returned `present_locations`.
All ... | f12679:m2 |
def prune_non_existent_outputs(compound_match_query): | if len(compound_match_query.match_queries) == <NUM_LIT:1>:<EOL><INDENT>return compound_match_query<EOL><DEDENT>elif len(compound_match_query.match_queries) == <NUM_LIT:0>:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>match_queries = []<EOL>for match_query in compound_mat... | Remove non-existent outputs from each MatchQuery in the given CompoundMatchQuery.
Each of the 2^n MatchQuery objects (except one) has been pruned to exclude some Traverse blocks,
For each of these, remove the outputs (that have been implicitly pruned away) from each
corresponding ConstructResult block.
... | f12679:m3 |
def _construct_location_to_filter_list(match_query): | <EOL>location_to_filters = {}<EOL>for match_traversal in match_query.match_traversals:<EOL><INDENT>for match_step in match_traversal:<EOL><INDENT>current_filter = match_step.where_block<EOL>if current_filter is not None:<EOL><INDENT>current_location = match_step.as_block.location<EOL>location_to_filters.setdefault(curr... | Return a dict mapping location -> list of filters applied at that location.
Args:
match_query: MatchQuery object from which to extract location -> filters dict
Returns:
dict mapping each location in match_query to a list of
Filter objects applied at that location | f12679:m4 |
def _filter_list_to_conjunction_expression(filter_list): | if not isinstance(filter_list, list):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'.format(filter_list))<EOL><DEDENT>if any((not isinstance(filter_block, Filter) for filter_block in filter_list)):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'.format(filter_list))<EOL><DEDENT>expression_list = [filter_block.predicate fo... | Convert a list of filters to an Expression that is the conjunction of all of them. | f12679:m5 |
def _apply_filters_to_first_location_occurrence(match_traversal, location_to_filters,<EOL>already_filtered_locations): | new_match_traversal = []<EOL>newly_filtered_locations = set()<EOL>for match_step in match_traversal:<EOL><INDENT>current_location = match_step.as_block.location<EOL>if current_location in newly_filtered_locations:<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'<EOL>.format(current_location, match_travers... | Apply all filters for a specific location into its first occurrence in a given traversal.
For each location in the given match traversal,
construct a conjunction of all filters applied to that location,
and apply the resulting Filter to the first instance of the location.
Args:
match_traversal... | f12679:m6 |
def collect_filters_to_first_location_occurrence(compound_match_query): | new_match_queries = []<EOL>for match_query in compound_match_query.match_queries:<EOL><INDENT>location_to_filters = _construct_location_to_filter_list(match_query)<EOL>already_filtered_locations = set()<EOL>new_match_traversals = []<EOL>for match_traversal in match_query.match_traversals:<EOL><INDENT>result = _apply_fi... | Collect all filters for a particular location to the first instance of the location.
Adding edge field non-exsistence filters in `_prune_traverse_using_omitted_locations` may
result in filters being applied to locations after their first occurence.
OrientDB does not resolve this behavior correctly. Therefo... | f12679:m7 |
def _update_context_field_binary_composition(present_locations, expression): | if not any((isinstance(expression.left, ContextField),<EOL>isinstance(expression.right, ContextField))):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(expression))<EOL><DEDENT>if isinstance(expression.left, ContextField):<EOL><INDENT>context_field = expression.left<EOL>location_name, _ = context... | Lower BinaryCompositions involving non-existent ContextFields to True.
Args:
present_locations: set of all locations in the current MatchQuery that have not been pruned
expression: BinaryComposition with at least one ContextField operand
Returns:
TrueLiteral iff either ContextField ope... | f12679:m8 |
def _simplify_non_context_field_binary_composition(expression): | if any((isinstance(expression.left, ContextField),<EOL>isinstance(expression.right, ContextField))):<EOL><INDENT>raise AssertionError(u'<STR_LIT>'<EOL>u'<STR_LIT>'.format(expression))<EOL><DEDENT>if expression.operator == u'<STR_LIT>':<EOL><INDENT>if expression.left == TrueLiteral or expression.right == TrueLiteral:<EO... | Return a simplified BinaryComposition if either operand is a TrueLiteral.
Args:
expression: BinaryComposition without any ContextField operand(s)
Returns:
simplified expression if the given expression is a disjunction/conjunction
and one of it's operands is a TrueLiteral,
and t... | f12679:m9 |
def _simplify_ternary_conditional(expression): | if expression.predicate == TrueLiteral:<EOL><INDENT>return expression.if_true<EOL><DEDENT>else:<EOL><INDENT>return expression<EOL><DEDENT> | Return the `if_true` clause if the predicate of the TernaryConditional is a TrueLiteral.
Args:
expression: TernaryConditional to be simplified.
Returns:
the if_true expression of the given TernaryConditional, if the predicate is True,
and the original TernaryConditional otherwise | f12679:m10 |
def _update_context_field_expression(present_locations, expression): | no_op_blocks = (ContextField, Literal, LocalField, UnaryTransformation, Variable)<EOL>if isinstance(expression, BinaryComposition):<EOL><INDENT>if isinstance(expression.left, ContextField) or isinstance(expression.right, ContextField):<EOL><INDENT>return _update_context_field_binary_composition(present_locations, expre... | Lower Expressions involving non-existent ContextFields to TrueLiteral and simplify result. | f12679:m11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.