idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
39,000
def _sanity_check_every_location_is_marked ( ir_blocks ) : found_start_block = False mark_location_blocks_count = 0 start_interval_types = ( QueryRoot , Traverse , Recurse , Fold ) end_interval_types = ( Backtrack , ConstructResult , Recurse , Traverse , Unfold ) for block in ir_blocks : if isinstance ( block , end_int...
Ensure that every new location is marked with a MarkLocation block .
39,001
def _sanity_check_coerce_type_outside_of_fold ( ir_blocks ) : is_in_fold = False for first_block , second_block in pairwise ( ir_blocks ) : if isinstance ( first_block , Fold ) : is_in_fold = True if not is_in_fold and isinstance ( first_block , CoerceType ) : if not isinstance ( second_block , ( MarkLocation , Filter ...
Ensure that CoerceType not in a
39,002
def validate_supported_property_type_id ( property_name , property_type_id ) : if property_type_id not in PROPERTY_TYPE_ID_TO_NAME : raise AssertionError ( u'Property "{}" has unsupported property type id: ' u'{}' . format ( property_name , property_type_id ) )
Ensure that the given property type_id is supported by the graph .
39,003
def _parse_bool_default_value ( property_name , default_value_string ) : lowercased_value_string = default_value_string . lower ( ) if lowercased_value_string in { '0' , 'false' } : return False elif lowercased_value_string in { '1' , 'true' } : return True else : raise AssertionError ( u'Unsupported default value for ...
Parse and return the default value for a boolean property .
39,004
def _parse_datetime_default_value ( property_name , default_value_string ) : parsed_value = time . strptime ( default_value_string , ORIENTDB_DATETIME_FORMAT ) return datetime . datetime ( parsed_value . tm_year , parsed_value . tm_mon , parsed_value . tm_mday , parsed_value . tm_hour , parsed_value . tm_min , parsed_v...
Parse and return the default value for a datetime property .
39,005
def _parse_date_default_value ( property_name , default_value_string ) : parsed_value = time . strptime ( default_value_string , ORIENTDB_DATE_FORMAT ) return datetime . date ( parsed_value . tm_year , parsed_value . tm_mon , parsed_value . tm_mday )
Parse and return the default value for a date property .
39,006
def parse_default_property_value ( property_name , property_type_id , default_value_string ) : if property_type_id == PROPERTY_TYPE_EMBEDDED_SET_ID and default_value_string == '{}' : return set ( ) elif property_type_id == PROPERTY_TYPE_EMBEDDED_LIST_ID and default_value_string == '[]' : return list ( ) elif ( property...
Parse the default value string into its proper form given the property type ID .
39,007
def _compile_graphql_generic ( language , lowering_func , query_emitter_func , schema , graphql_string , type_equivalence_hints , compiler_metadata ) : ir_and_metadata = graphql_to_ir ( schema , graphql_string , type_equivalence_hints = type_equivalence_hints ) lowered_ir_blocks = lowering_func ( ir_and_metadata . ir_b...
Compile the GraphQL input lowering and emitting the query using the given functions .
39,008
def scalar_leaf_only ( operator ) : def decorator ( f ) : @ wraps ( f ) def wrapper ( filter_operation_info , context , parameters , * args , ** kwargs ) : if 'operator' in kwargs : current_operator = kwargs [ 'operator' ] else : current_operator = operator if not is_leaf_type ( filter_operation_info . field_type ) : r...
Ensure the filter function is only applied to scalar leaf types .
39,009
def vertex_field_only ( operator ) : def decorator ( f ) : @ wraps ( f ) def wrapper ( filter_operation_info , context , parameters , * args , ** kwargs ) : if 'operator' in kwargs : current_operator = kwargs [ 'operator' ] else : current_operator = operator if not is_vertex_field_type ( filter_operation_info . field_t...
Ensure the filter function is only applied to vertex field types .
39,010
def takes_parameters ( count ) : def decorator ( f ) : @ wraps ( f ) def wrapper ( filter_operation_info , location , context , parameters , * args , ** kwargs ) : if len ( parameters ) != count : raise GraphQLCompilationError ( u'Incorrect number of parameters, expected {} got ' u'{}: {}' . format ( count , len ( para...
Ensure the filter function has count parameters specified .
39,011
def _represent_argument ( directive_location , context , argument , inferred_type ) : argument_name = argument [ 1 : ] validate_safe_string ( argument_name ) if is_variable_argument ( argument ) : existing_type = context [ 'inputs' ] . get ( argument_name , inferred_type ) if not inferred_type . is_same_type ( existing...
Return a two - element tuple that represents the argument to the directive being processed .
39,012
def _process_comparison_filter_directive ( filter_operation_info , location , context , parameters , operator = None ) : comparison_operators = { u'=' , u'!=' , u'>' , u'<' , u'>=' , u'<=' } if operator not in comparison_operators : raise AssertionError ( u'Expected a valid comparison operator ({}), but got ' u'{}' . f...
Return a Filter basic block that performs the given comparison against the property field .
39,013
def _process_has_edge_degree_filter_directive ( filter_operation_info , location , context , parameters ) : if isinstance ( filter_operation_info . field_ast , InlineFragment ) : raise AssertionError ( u'Received InlineFragment AST node in "has_edge_degree" filter ' u'handler. This should have been caught earlier: ' u'...
Return a Filter basic block that checks the degree of the edge to the given vertex field .
39,014
def _process_name_or_alias_filter_directive ( filter_operation_info , location , context , parameters ) : filtered_field_type = filter_operation_info . field_type if isinstance ( filtered_field_type , GraphQLUnionType ) : raise GraphQLCompilationError ( u'Cannot apply "name_or_alias" to union type ' u'{}' . format ( fi...
Return a Filter basic block that checks for a match against an Entity s name or alias .
39,015
def _process_between_filter_directive ( filter_operation_info , location , context , parameters ) : filtered_field_type = filter_operation_info . field_type filtered_field_name = filter_operation_info . field_name argument_inferred_type = strip_non_null_from_type ( filtered_field_type ) arg1_expression , arg1_non_exist...
Return a Filter basic block that checks that a field is between two values inclusive .
39,016
def _process_in_collection_filter_directive ( filter_operation_info , location , context , parameters ) : filtered_field_type = filter_operation_info . field_type filtered_field_name = filter_operation_info . field_name argument_inferred_type = GraphQLList ( strip_non_null_from_type ( filtered_field_type ) ) argument_e...
Return a Filter basic block that checks for a value s existence in a collection .
39,017
def _process_has_substring_filter_directive ( filter_operation_info , location , context , parameters ) : filtered_field_type = filter_operation_info . field_type filtered_field_name = filter_operation_info . field_name if not strip_non_null_from_type ( filtered_field_type ) . is_same_type ( GraphQLString ) : raise Gra...
Return a Filter basic block that checks if the directive arg is a substring of the field .
39,018
def _process_contains_filter_directive ( filter_operation_info , location , context , parameters ) : filtered_field_type = filter_operation_info . field_type filtered_field_name = filter_operation_info . field_name base_field_type = strip_non_null_from_type ( filtered_field_type ) if not isinstance ( base_field_type , ...
Return a Filter basic block that checks if the directive arg is contained in the field .
39,019
def _process_intersects_filter_directive ( filter_operation_info , location , context , parameters ) : filtered_field_type = filter_operation_info . field_type filtered_field_name = filter_operation_info . field_name argument_inferred_type = strip_non_null_from_type ( filtered_field_type ) if not isinstance ( argument_...
Return a Filter basic block that checks if the directive arg and the field intersect .
39,020
def is_filter_with_outer_scope_vertex_field_operator ( directive ) : if directive . name . value != 'filter' : return False op_name , _ = _get_filter_op_name_and_values ( directive ) return op_name in OUTER_SCOPE_VERTEX_FIELD_OPERATORS
Return True if we have a filter directive whose operator applies to the outer scope .
39,021
def process_filter_directive ( filter_operation_info , location , context ) : op_name , operator_params = _get_filter_op_name_and_values ( filter_operation_info . directive ) non_comparison_filters = { u'name_or_alias' : _process_name_or_alias_filter_directive , u'between' : _process_between_filter_directive , u'in_col...
Return a Filter basic block that corresponds to the filter operation in the directive .
39,022
def get_schema_type_name ( node , context ) : query_path = node . query_path if query_path not in context . query_path_to_location_info : raise AssertionError ( u'Unable to find type name for query path {} with context {}.' . format ( query_path , context ) ) location_info = context . query_path_to_location_info [ quer...
Return the GraphQL type name of a node .
39,023
def get_node_at_path ( query_path , context ) : if query_path not in context . query_path_to_node : raise AssertionError ( u'Unable to find SqlNode for query path {} with context {}.' . format ( query_path , context ) ) node = context . query_path_to_node [ query_path ] return node
Return the SqlNode associated with the query path .
39,024
def try_get_column ( column_name , node , context ) : selectable = get_node_selectable ( node , context ) if not hasattr ( selectable , 'c' ) : raise AssertionError ( u'Selectable "{}" does not have a column collection. Context is {}.' . format ( selectable , context ) ) return selectable . c . get ( column_name , None...
Attempt to get a column by name from the selectable .
39,025
def get_column ( column_name , node , context ) : column = try_get_column ( column_name , node , context ) if column is None : selectable = get_node_selectable ( node , context ) raise AssertionError ( u'Column "{}" not found in selectable "{}". Columns present are {}. ' u'Context is {}.' . format ( column_name , selec...
Get a column by name from the selectable .
39,026
def get_unique_directives ( ast ) : if not ast . directives : return dict ( ) result = dict ( ) for directive_obj in ast . directives : directive_name = directive_obj . name . value if directive_name in ALLOWED_DUPLICATED_DIRECTIVES : pass elif directive_name in result : raise GraphQLCompilationError ( u'Directive was ...
Return a dict of directive name to directive object for the given AST node .
39,027
def get_local_filter_directives ( ast , current_schema_type , inner_vertex_fields ) : result = [ ] if ast . directives : for directive_obj in ast . directives : if directive_obj . name . value == 'filter' : filtered_field_name = get_ast_field_name_or_none ( ast ) if is_filter_with_outer_scope_vertex_field_operator ( di...
Get all filter directives that apply to the current field .
39,028
def validate_property_directives ( directives ) : for directive_name in six . iterkeys ( directives ) : if directive_name in VERTEX_ONLY_DIRECTIVES : raise GraphQLCompilationError ( u'Found vertex-only directive {} set on property.' . format ( directive_name ) )
Validate the directives that appear at a property field .
39,029
def validate_vertex_directives ( directives ) : for directive_name in six . iterkeys ( directives ) : if directive_name in PROPERTY_ONLY_DIRECTIVES : raise GraphQLCompilationError ( u'Found property-only directive {} set on vertex.' . format ( directive_name ) )
Validate the directives that appear at a vertex field .
39,030
def validate_root_vertex_directives ( root_ast ) : directives_present_at_root = set ( ) for directive_obj in root_ast . directives : directive_name = directive_obj . name . value if is_filter_with_outer_scope_vertex_field_operator ( directive_obj ) : raise GraphQLCompilationError ( u'Found a filter directive with an op...
Validate the directives that appear at the root vertex field .
39,031
def validate_vertex_field_directive_interactions ( parent_location , vertex_field_name , directives ) : fold_directive = directives . get ( 'fold' , None ) optional_directive = directives . get ( 'optional' , None ) output_source_directive = directives . get ( 'output_source' , None ) recurse_directive = directives . g...
Ensure that the specified vertex field directives are not mutually disallowed .
39,032
def validate_vertex_field_directive_in_context ( parent_location , vertex_field_name , directives , context ) : fold_directive = directives . get ( 'fold' , None ) optional_directive = directives . get ( 'optional' , None ) recurse_directive = directives . get ( 'recurse' , None ) output_source_directive = directives ....
Ensure that the specified vertex field directives are allowed in the current context .
39,033
def _safe_match_string ( value ) : if not isinstance ( value , six . string_types ) : if isinstance ( value , bytes ) : value = value . decode ( 'utf-8' ) else : raise GraphQLInvalidArgumentError ( u'Attempting to convert a non-string into a string: ' u'{}' . format ( value ) ) return json . dumps ( value )
Sanitize and represent a string argument in MATCH .
39,034
def _safe_match_date_and_datetime ( graphql_type , expected_python_types , value ) : value_type = type ( value ) if not any ( value_type == x for x in expected_python_types ) : raise GraphQLInvalidArgumentError ( u'Expected value to be exactly one of ' u'python types {}, but was {}: ' u'{}' . format ( expected_python_t...
Represent date and datetime objects as MATCH strings .
39,035
def _safe_match_list ( inner_type , argument_value ) : stripped_type = strip_non_null_from_type ( inner_type ) if isinstance ( stripped_type , GraphQLList ) : raise GraphQLInvalidArgumentError ( u'MATCH does not currently support nested lists, ' u'but inner type was {}: ' u'{}' . format ( inner_type , argument_value ) ...
Represent the list of inner_type objects in MATCH form .
39,036
def insert_arguments_into_match_query ( compilation_result , arguments ) : if compilation_result . language != MATCH_LANGUAGE : raise AssertionError ( u'Unexpected query output language: {}' . format ( compilation_result ) ) base_query = compilation_result . query argument_types = compilation_result . input_metadata sa...
Insert the arguments into the compiled MATCH query to form a complete query .
39,037
def get_table ( self , schema_type ) : table_name = schema_type . lower ( ) if not self . has_table ( table_name ) : raise exceptions . GraphQLCompilationError ( 'No Table found in SQLAlchemy metadata for table name "{}"' . format ( table_name ) ) return self . table_name_to_table [ table_name ]
Retrieve a SQLAlchemy table based on the supplied GraphQL schema type name .
39,038
def _per_location_tuple_to_step ( ir_tuple ) : root_block = ir_tuple [ 0 ] if not isinstance ( root_block , root_block_types ) : raise AssertionError ( u'Unexpected root block type for MatchStep: ' u'{} {}' . format ( root_block , ir_tuple ) ) coerce_type_block = None where_block = None as_block = None for block in ir_...
Construct a MatchStep from a tuple of its constituent blocks .
39,039
def _split_ir_into_match_steps ( pruned_ir_blocks ) : output = [ ] current_tuple = None for block in pruned_ir_blocks : if isinstance ( block , OutputSource ) : continue elif isinstance ( block , root_block_types ) : if current_tuple is not None : output . append ( current_tuple ) current_tuple = ( block , ) elif isins...
Split a list of IR blocks into per - location MATCH steps .
39,040
def _split_match_steps_into_match_traversals ( match_steps ) : output = [ ] current_list = None for step in match_steps : if isinstance ( step . root_block , QueryRoot ) : if current_list is not None : output . append ( current_list ) current_list = [ step ] else : current_list . append ( step ) if current_list is None...
Split a list of MatchSteps into multiple lists each denoting a single MATCH traversal .
39,041
def convert_to_match_query ( ir_blocks ) : output_block = ir_blocks [ - 1 ] if not isinstance ( output_block , ConstructResult ) : raise AssertionError ( u'Expected last IR block to be ConstructResult, found: ' u'{} {}' . format ( output_block , ir_blocks ) ) ir_except_output = ir_blocks [ : - 1 ] folds , ir_except_out...
Convert the list of IR blocks into a MatchQuery object for easier manipulation .
39,042
def insert_arguments_into_sql_query ( compilation_result , arguments ) : if compilation_result . language != SQL_LANGUAGE : raise AssertionError ( u'Unexpected query output language: {}' . format ( compilation_result ) ) base_query = compilation_result . query return base_query . params ( ** arguments )
Insert the arguments into the compiled SQL query to form a complete query .
39,043
def convert_coerce_type_to_instanceof_filter ( coerce_type_block ) : coerce_type_target = get_only_element_from_collection ( coerce_type_block . target_class ) new_predicate = BinaryComposition ( u'INSTANCEOF' , LocalField ( '@this' ) , Literal ( coerce_type_target ) ) return Filter ( new_predicate )
Create an INSTANCEOF Filter block from a CoerceType block .
39,044
def convert_coerce_type_and_add_to_where_block ( coerce_type_block , where_block ) : instanceof_filter = convert_coerce_type_to_instanceof_filter ( coerce_type_block ) if where_block : return Filter ( BinaryComposition ( u'&&' , instanceof_filter . predicate , where_block . predicate ) ) else : return instanceof_filter
Create an INSTANCEOF Filter from a CoerceType adding to an existing Filter if any .
39,045
def expression_list_to_conjunction ( expression_list ) : if not isinstance ( expression_list , list ) : raise AssertionError ( u'Expected `list`, Received {}.' . format ( expression_list ) ) if len ( expression_list ) == 0 : return TrueLiteral if not isinstance ( expression_list [ 0 ] , Expression ) : raise AssertionEr...
Convert a list of expressions to an Expression that is the conjunction of all of them .
39,046
def construct_where_filter_predicate ( query_metadata_table , simple_optional_root_info ) : inner_location_name_to_where_filter = { } for root_location , root_info_dict in six . iteritems ( simple_optional_root_info ) : inner_location_name = root_info_dict [ 'inner_location_name' ] edge_field = root_info_dict [ 'edge_f...
Return an Expression that is True if and only if each simple optional filter is True .
39,047
def construct_optional_traversal_tree ( complex_optional_roots , location_to_optional_roots ) : tree = OptionalTraversalTree ( complex_optional_roots ) for optional_root_locations_stack in six . itervalues ( location_to_optional_roots ) : tree . insert ( list ( optional_root_locations_stack ) ) return tree
Return a tree of complex optional root locations .
39,048
def validate ( self ) : if not isinstance ( self . field , LocalField ) : raise TypeError ( u'Expected LocalField field, got: {} {}' . format ( type ( self . field ) . __name__ , self . field ) ) if not isinstance ( self . lower_bound , Expression ) : raise TypeError ( u'Expected Expression lower_bound, got: {} {}' . f...
Validate that the Between Expression is correctly representable .
39,049
def to_match ( self ) : template = u'({field_name} BETWEEN {lower_bound} AND {upper_bound})' return template . format ( field_name = self . field . to_match ( ) , lower_bound = self . lower_bound . to_match ( ) , upper_bound = self . upper_bound . to_match ( ) )
Return a unicode object with the MATCH representation of this BetweenClause .
39,050
def insert ( self , optional_root_locations_path ) : encountered_simple_optional = False parent_location = self . _root_location for optional_root_location in optional_root_locations_path : if encountered_simple_optional : raise AssertionError ( u'Encountered simple optional root location {} in path, but' u'further loc...
Insert a path of optional Locations into the tree .
39,051
def emit_code_from_ir ( sql_query_tree , compiler_metadata ) : context = CompilationContext ( query_path_to_selectable = dict ( ) , query_path_to_location_info = sql_query_tree . query_path_to_location_info , query_path_to_output_fields = sql_query_tree . query_path_to_output_fields , query_path_to_filters = sql_query_...
Return a SQLAlchemy Query from a passed SqlQueryTree .
39,052
def _create_table_and_update_context ( node , context ) : schema_type_name = sql_context_helpers . get_schema_type_name ( node , context ) table = context . compiler_metadata . get_table ( schema_type_name ) . alias ( ) context . query_path_to_selectable [ node . query_path ] = table return table
Create an aliased table for a SqlNode .
39,053
def _create_query ( node , context ) : visited_nodes = [ node ] output_columns = _get_output_columns ( visited_nodes , context ) filters = _get_filters ( visited_nodes , context ) selectable = sql_context_helpers . get_node_selectable ( node , context ) query = select ( output_columns ) . select_from ( selectable ) . w...
Create a query from a SqlNode .
39,054
def _get_output_columns ( nodes , context ) : columns = [ ] for node in nodes : for sql_output in sql_context_helpers . get_outputs ( node , context ) : field_name = sql_output . field_name column = sql_context_helpers . get_column ( field_name , node , context ) column = column . label ( sql_output . output_name ) col...
Get the output columns for a list of SqlNodes .
39,055
def _get_filters ( nodes , context ) : filters = [ ] for node in nodes : for filter_block in sql_context_helpers . get_filters ( node , context ) : filter_sql_expression = _transform_filter_to_sql ( filter_block , node , context ) filters . append ( filter_sql_expression ) return filters
Get filters to apply to a list of SqlNodes .
39,056
def _transform_filter_to_sql ( filter_block , node , context ) : expression = filter_block . predicate return _expression_to_sql ( expression , node , context )
Transform a Filter block to its corresponding SQLAlchemy expression .
39,057
def _expression_to_sql ( expression , node , context ) : _expression_transformers = { expressions . LocalField : _transform_local_field_to_expression , expressions . Variable : _transform_variable_to_expression , expressions . Literal : _transform_literal_to_expression , expressions . BinaryComposition : _transform_bin...
Recursively transform a Filter block predicate to its SQLAlchemy expression representation .
39,058
def _transform_binary_composition_to_expression ( expression , node , context ) : if expression . operator not in constants . SUPPORTED_OPERATORS : raise NotImplementedError ( u'Filter operation "{}" is not supported by the SQL backend.' . format ( expression . operator ) ) sql_operator = constants . SUPPORTED_OPERATOR...
Transform a BinaryComposition compiler expression into a SQLAlchemy expression .
39,059
def _transform_variable_to_expression ( expression , node , context ) : variable_name = expression . variable_name if not variable_name . startswith ( u'$' ) : raise AssertionError ( u'Unexpectedly received variable name {} that is not ' u'prefixed with "$"' . format ( variable_name ) ) return bindparam ( variable_name...
Transform a Variable compiler expression into its SQLAlchemy expression representation .
39,060
def _transform_local_field_to_expression ( expression , node , context ) : column_name = expression . field_name column = sql_context_helpers . get_column ( column_name , node , context ) return column
Transform a LocalField compiler expression into its SQLAlchemy expression representation .
39,061
def lower_context_field_existence ( ir_blocks , query_metadata_table ) : def regular_visitor_fn ( expression ) : if not isinstance ( expression , ContextFieldExistence ) : return expression location_type = query_metadata_table . get_location_info ( expression . location ) . type return BinaryComposition ( u'!=' , Conte...
Lower ContextFieldExistence expressions into lower - level expressions .
39,062
def optimize_boolean_expression_comparisons ( ir_blocks ) : operator_inverses = { u'=' : u'!=' , u'!=' : u'=' , } def visitor_fn ( expression ) : if not isinstance ( expression , BinaryComposition ) : return expression left_is_binary_composition = isinstance ( expression . left , BinaryComposition ) right_is_binary_com...
Optimize comparisons of a boolean binary comparison expression against a boolean literal .
39,063
def extract_simple_optional_location_info ( ir_blocks , complex_optional_roots , location_to_optional_roots ) : location_to_preceding_optional_root_iteritems = six . iteritems ( { location : optional_root_locations_stack [ - 1 ] for location , optional_root_locations_stack in six . iteritems ( location_to_optional_root...
Construct a map from simple optional locations to their inner location and traversed edge .
39,064
def remove_end_optionals ( ir_blocks ) : new_ir_blocks = [ ] for block in ir_blocks : if not isinstance ( block , EndOptional ) : new_ir_blocks . append ( block ) return new_ir_blocks
Return a list of IR blocks as a copy of the original with EndOptional blocks removed .
39,065
def validate ( self ) : super ( OutputContextVertex , self ) . validate ( ) if self . location . field is not None : raise ValueError ( u'Expected location at a vertex, but got: {}' . format ( self . location ) )
Validate that the OutputContextVertex is correctly representable .
39,066
def lower_has_substring_binary_compositions ( ir_blocks ) : def visitor_fn ( expression ) : if not isinstance ( expression , BinaryComposition ) or expression . operator != u'has_substring' : return expression return BinaryComposition ( u'LIKE' , expression . left , BinaryComposition ( u'+' , Literal ( '%' ) , BinaryCo...
Lower Filter blocks that use the has_substring operation into MATCH - representable form .
39,067
def truncate_repeated_single_step_traversals ( match_query ) : new_match_traversals = [ ] visited_locations = set ( ) for current_match_traversal in match_query . match_traversals : ignore_traversal = False if len ( current_match_traversal ) == 1 : single_step = current_match_traversal [ 0 ] if single_step . as_block i...
Truncate one - step traversals that overlap a previous traversal location .
39,068
def _flatten_location_translations ( location_translations ) : sources_to_process = set ( six . iterkeys ( location_translations ) ) def _update_translation ( source ) : destination = location_translations [ source ] if destination not in location_translations : return destination else : sources_to_process . discard ( ...
If location A translates to B and B to C then make A translate directly to C .
39,069
def _translate_equivalent_locations ( match_query , location_translations ) : new_match_traversals = [ ] def visitor_fn ( expression ) : if isinstance ( expression , ( ContextField , GlobalContextField ) ) : old_location = expression . location . at_vertex ( ) new_location = location_translations . get ( old_location ,...
Translate Location objects into their equivalent locations based on the given dict .
39,070
def lower_folded_coerce_types_into_filter_blocks ( folded_ir_blocks ) : new_folded_ir_blocks = [ ] for block in folded_ir_blocks : if isinstance ( block , CoerceType ) : new_block = convert_coerce_type_to_instanceof_filter ( block ) else : new_block = block new_folded_ir_blocks . append ( new_block ) return new_folded_...
Lower CoerceType blocks into INSTANCEOF Filter blocks . Indended for folded IR blocks .
39,071
def remove_backtrack_blocks_from_fold ( folded_ir_blocks ) : new_folded_ir_blocks = [ ] for block in folded_ir_blocks : if not isinstance ( block , Backtrack ) : new_folded_ir_blocks . append ( block ) return new_folded_ir_blocks
Return a list of IR blocks with all Backtrack blocks removed .
39,072
def truncate_repeated_single_step_traversals_in_sub_queries ( compound_match_query ) : lowered_match_queries = [ ] for match_query in compound_match_query . match_queries : new_match_query = truncate_repeated_single_step_traversals ( match_query ) lowered_match_queries . append ( new_match_query ) return compound_match...
For each sub - query remove one - step traversals that overlap a previous traversal location .
39,073
def _prune_traverse_using_omitted_locations ( match_traversal , omitted_locations , complex_optional_roots , location_to_optional_roots ) : new_match_traversal = [ ] for step in match_traversal : new_step = step if isinstance ( step . root_block , Traverse ) and step . root_block . optional : current_location = step . ...
Return a prefix of the given traverse excluding any blocks after an omitted optional .
39,074
def convert_optional_traversals_to_compound_match_query ( match_query , complex_optional_roots , location_to_optional_roots ) : tree = construct_optional_traversal_tree ( complex_optional_roots , location_to_optional_roots ) rooted_optional_root_location_subsets = tree . get_all_rooted_subtrees_as_lists ( ) omitted_loc...
Return 2^n distinct MatchQuery objects in a CompoundMatchQuery .
39,075
def _get_present_locations ( match_traversals ) : present_locations = set ( ) present_non_optional_locations = set ( ) for match_traversal in match_traversals : for step in match_traversal : if step . as_block is not None : location_name , _ = step . as_block . location . get_location_name ( ) present_locations . add (...
Return the set of locations and non - optional locations present in the given match traversals .
39,076
def prune_non_existent_outputs ( compound_match_query ) : if len ( compound_match_query . match_queries ) == 1 : return compound_match_query elif len ( compound_match_query . match_queries ) == 0 : raise AssertionError ( u'Received CompoundMatchQuery with ' u'an empty list of MatchQuery objects.' ) else : match_queries...
Remove non - existent outputs from each MatchQuery in the given CompoundMatchQuery .
39,077
def _construct_location_to_filter_list ( match_query ) : location_to_filters = { } for match_traversal in match_query . match_traversals : for match_step in match_traversal : current_filter = match_step . where_block if current_filter is not None : current_location = match_step . as_block . location location_to_filters...
Return a dict mapping location - > list of filters applied at that location .
39,078
def _filter_list_to_conjunction_expression ( filter_list ) : if not isinstance ( filter_list , list ) : raise AssertionError ( u'Expected `list`, Received: {}.' . format ( filter_list ) ) if any ( ( not isinstance ( filter_block , Filter ) for filter_block in filter_list ) ) : raise AssertionError ( u'Expected list of ...
Convert a list of filters to an Expression that is the conjunction of all of them .
39,079
def _apply_filters_to_first_location_occurrence ( match_traversal , location_to_filters , already_filtered_locations ) : new_match_traversal = [ ] newly_filtered_locations = set ( ) for match_step in match_traversal : current_location = match_step . as_block . location if current_location in newly_filtered_locations : ...
Apply all filters for a specific location into its first occurrence in a given traversal .
39,080
def collect_filters_to_first_location_occurrence ( compound_match_query ) : new_match_queries = [ ] for match_query in compound_match_query . match_queries : location_to_filters = _construct_location_to_filter_list ( match_query ) already_filtered_locations = set ( ) new_match_traversals = [ ] for match_traversal in ma...
Collect all filters for a particular location to the first instance of the location .
39,081
def _update_context_field_binary_composition ( present_locations , expression ) : if not any ( ( isinstance ( expression . left , ContextField ) , isinstance ( expression . right , ContextField ) ) ) : raise AssertionError ( u'Received a BinaryComposition {} without any ContextField ' u'operands. This should never happ...
Lower BinaryCompositions involving non - existent ContextFields to True .
39,082
def _simplify_non_context_field_binary_composition ( expression ) : if any ( ( isinstance ( expression . left , ContextField ) , isinstance ( expression . right , ContextField ) ) ) : raise AssertionError ( u'Received a BinaryComposition {} with a ContextField ' u'operand. This should never happen.' . format ( expressi...
Return a simplified BinaryComposition if either operand is a TrueLiteral .
39,083
def _update_context_field_expression ( present_locations , expression ) : no_op_blocks = ( ContextField , Literal , LocalField , UnaryTransformation , Variable ) if isinstance ( expression , BinaryComposition ) : if isinstance ( expression . left , ContextField ) or isinstance ( expression . right , ContextField ) : re...
Lower Expressions involving non - existent ContextFields to TrueLiteral and simplify result .
39,084
def _lower_non_existent_context_field_filters ( match_traversals , visitor_fn ) : new_match_traversals = [ ] for match_traversal in match_traversals : new_match_traversal = [ ] for step in match_traversal : if step . where_block is not None : new_filter = step . where_block . visit_and_update_expressions ( visitor_fn )...
Return new match traversals lowering filters involving non - existent ContextFields .
39,085
def lower_context_field_expressions ( compound_match_query ) : if len ( compound_match_query . match_queries ) == 0 : raise AssertionError ( u'Received CompoundMatchQuery {} with no MatchQuery objects.' . format ( compound_match_query ) ) elif len ( compound_match_query . match_queries ) == 1 : return compound_match_qu...
Lower Expressons involving non - existent ContextFields .
39,086
def _validate_edges_do_not_have_extra_links ( class_name , properties ) : for property_name , property_descriptor in six . iteritems ( properties ) : if property_name in { EDGE_SOURCE_PROPERTY_NAME , EDGE_DESTINATION_PROPERTY_NAME } : continue if property_descriptor . type_id == PROPERTY_TYPE_LINK_ID : raise IllegalSch...
Validate that edges do not have properties of Link type that aren t the edge endpoints .
39,087
def _validate_property_names ( class_name , properties ) : for property_name in properties : if not property_name or property_name . startswith ( ILLEGAL_PROPERTY_NAME_PREFIXES ) : raise IllegalSchemaStateError ( u'Class "{}" has a property with an illegal name: ' u'{}' . format ( class_name , property_name ) )
Validate that properties do not have names that may cause problems in the GraphQL schema .
39,088
def _validate_collections_have_default_values ( class_name , property_name , property_descriptor ) : if property_descriptor . type_id in COLLECTION_PROPERTY_TYPES : if property_descriptor . default is None : raise IllegalSchemaStateError ( u'Class "{}" has a property "{}" of collection type with ' u'no default value.' ...
Validate that if the property is of collection type it has a specified default value .
39,089
def get_superclasses_from_class_definition ( class_definition ) : superclasses = class_definition . get ( 'superClasses' , None ) if superclasses : return list ( superclasses ) superclass = class_definition . get ( 'superClass' , None ) if superclass : return [ superclass ] return [ ]
Extract a list of all superclass names from a class definition dict .
39,090
def freeze ( self ) : self . in_connections = frozenset ( self . in_connections ) self . out_connections = frozenset ( self . out_connections )
Make the SchemaElement s connections immutable .
39,091
def get_default_property_values ( self , classname ) : schema_element = self . get_element_by_class_name ( classname ) result = { property_name : property_descriptor . default for property_name , property_descriptor in six . iteritems ( schema_element . properties ) } if schema_element . is_edge : result . pop ( EDGE_S...
Return a dict with default values for all properties declared on this class .
39,092
def _get_property_values_with_defaults ( self , classname , property_values ) : final_values = self . get_default_property_values ( classname ) final_values . update ( property_values ) return final_values
Return the property values for the class with default values applied where needed .
39,093
def get_element_by_class_name_or_raise ( self , class_name ) : if class_name not in self . _elements : raise InvalidClassError ( u'Class does not exist: {}' . format ( class_name ) ) return self . _elements [ class_name ]
Return the SchemaElement for the specified class name asserting that it exists .
39,094
def get_vertex_schema_element_or_raise ( self , vertex_classname ) : schema_element = self . get_element_by_class_name_or_raise ( vertex_classname ) if not schema_element . is_vertex : raise InvalidClassError ( u'Non-vertex class provided: {}' . format ( vertex_classname ) ) return schema_element
Return the schema element with the given name asserting that it s of vertex type .
39,095
def get_edge_schema_element_or_raise ( self , edge_classname ) : schema_element = self . get_element_by_class_name_or_raise ( edge_classname ) if not schema_element . is_edge : raise InvalidClassError ( u'Non-edge class provided: {}' . format ( edge_classname ) ) return schema_element
Return the schema element with the given name asserting that it s of edge type .
39,096
def validate_is_non_abstract_vertex_type ( self , vertex_classname ) : element = self . get_vertex_schema_element_or_raise ( vertex_classname ) if element . abstract : raise InvalidClassError ( u'Expected a non-abstract vertex class, but {} is abstract' . format ( vertex_classname ) )
Validate that a vertex classname corresponds to a non - abstract vertex class .
39,097
def validate_is_non_abstract_edge_type ( self , edge_classname ) : element = self . get_edge_schema_element_or_raise ( edge_classname ) if element . abstract : raise InvalidClassError ( u'Expected a non-abstract vertex class, but {} is abstract' . format ( edge_classname ) )
Validate that a edge classname corresponds to a non - abstract edge class .
39,098
def validate_properties_exist ( self , classname , property_names ) : schema_element = self . get_element_by_class_name ( classname ) requested_properties = set ( property_names ) available_properties = set ( schema_element . properties . keys ( ) ) non_existent_properties = requested_properties - available_properties ...
Validate that the specified property names are indeed defined on the given class .
39,099
def _split_classes_by_kind ( self , class_name_to_definition ) : for class_name in class_name_to_definition : inheritance_set = self . _inheritance_sets [ class_name ] is_vertex = ORIENTDB_BASE_VERTEX_CLASS_NAME in inheritance_set is_edge = ORIENTDB_BASE_EDGE_CLASS_NAME in inheritance_set if is_vertex and is_edge : rai...
Assign each class to the vertex edge or non - graph type sets based on its kind .