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_interval_types ) and found_start_block : found_start_block = False if mark_location_blocks_count != 1 : raise AssertionError ( u'Expected 1 MarkLocation block between traversals, found: ' u'{} {}' . format ( mark_location_blocks_count , ir_blocks ) ) if isinstance ( block , MarkLocation ) : mark_location_blocks_count += 1 elif isinstance ( block , start_interval_types ) : found_start_block = True mark_location_blocks_count = 0 | 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 ) ) : raise AssertionError ( u'Expected MarkLocation or Filter after CoerceType, ' u'but none was found: {}' . format ( ir_blocks ) ) if isinstance ( second_block , Unfold ) : is_in_fold = False | 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 boolean property "{}": ' u'{}' . format ( property_name , default_value_string ) ) | 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_value . tm_sec , 0 , None ) | 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_type_id == PROPERTY_TYPE_STRING_ID and isinstance ( default_value_string , six . string_types ) ) : return default_value_string elif property_type_id == PROPERTY_TYPE_BOOLEAN_ID : return _parse_bool_default_value ( property_name , default_value_string ) elif property_type_id == PROPERTY_TYPE_DATETIME_ID : return _parse_datetime_default_value ( property_name , default_value_string ) elif property_type_id == PROPERTY_TYPE_DATE_ID : return _parse_date_default_value ( property_name , default_value_string ) else : raise AssertionError ( u'Unsupported default value for property "{}" with type id {}: ' u'{}' . format ( property_name , property_type_id , default_value_string ) ) | 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_blocks , ir_and_metadata . query_metadata_table , type_equivalence_hints = type_equivalence_hints ) query = query_emitter_func ( lowered_ir_blocks , compiler_metadata ) return CompilationResult ( query = query , language = language , output_metadata = ir_and_metadata . output_metadata , input_metadata = ir_and_metadata . input_metadata ) | 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 ) : raise GraphQLCompilationError ( u'Cannot apply "{}" filter to non-leaf type' u'{}' . format ( current_operator , filter_operation_info ) ) return f ( filter_operation_info , context , parameters , * args , ** kwargs ) return wrapper return decorator | 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_type ) : raise GraphQLCompilationError ( u'Cannot apply "{}" filter to non-vertex field: ' u'{}' . format ( current_operator , filter_operation_info . field_name ) ) return f ( filter_operation_info , context , parameters , * args , ** kwargs ) return wrapper return decorator | 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 ( parameters ) , parameters ) ) return f ( filter_operation_info , location , context , parameters , * args , ** kwargs ) return wrapper return decorator | 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_type ) : raise GraphQLCompilationError ( u'Incompatible types inferred for argument {}. ' u'The argument cannot simultaneously be ' u'{} and {}.' . format ( argument , existing_type , inferred_type ) ) context [ 'inputs' ] [ argument_name ] = inferred_type return ( expressions . Variable ( argument , inferred_type ) , None ) elif is_tag_argument ( argument ) : argument_context = context [ 'tags' ] . get ( argument_name , None ) if argument_context is None : raise GraphQLCompilationError ( u'Undeclared argument used: {}' . format ( argument ) ) location = argument_context [ 'location' ] optional = argument_context [ 'optional' ] tag_inferred_type = argument_context [ 'type' ] if location is None : raise AssertionError ( u'Argument declared without location: {}' . format ( argument_name ) ) if location . field is None : raise AssertionError ( u'Argument location is not a property field: {}' . format ( location ) ) if not inferred_type . is_same_type ( tag_inferred_type ) : raise GraphQLCompilationError ( u'The inferred type of the matching @tag directive does ' u'not match the inferred required type for this filter: ' u'{} vs {}' . format ( tag_inferred_type , inferred_type ) ) field_is_local = directive_location . at_vertex ( ) == location . at_vertex ( ) non_existence_expression = None if optional : if field_is_local : non_existence_expression = expressions . FalseLiteral else : non_existence_expression = expressions . BinaryComposition ( u'=' , expressions . ContextFieldExistence ( location . at_vertex ( ) ) , expressions . FalseLiteral ) if field_is_local : representation = expressions . LocalField ( argument_name ) else : representation = expressions . ContextField ( location , tag_inferred_type ) return ( representation , non_existence_expression ) else : raise GraphQLCompilationError ( u'Non-argument type found: {}' . format ( argument ) ) | 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'{}' . format ( comparison_operators , operator ) ) 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 ) argument_expression , non_existence_expression = _represent_argument ( location , context , parameters [ 0 ] , argument_inferred_type ) comparison_expression = expressions . BinaryComposition ( operator , expressions . LocalField ( filtered_field_name ) , argument_expression ) final_expression = None if non_existence_expression is not None : final_expression = expressions . BinaryComposition ( u'||' , non_existence_expression , comparison_expression ) else : final_expression = comparison_expression return blocks . Filter ( final_expression ) | 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'{}' . format ( filter_operation_info . field_ast ) ) filtered_field_name = filter_operation_info . field_name if filtered_field_name is None or not is_vertex_field_name ( filtered_field_name ) : raise AssertionError ( u'Invalid value for "filtered_field_name" in "has_edge_degree" ' u'filter: {}' . format ( filtered_field_name ) ) if not is_vertex_field_type ( filter_operation_info . field_type ) : raise AssertionError ( u'Invalid value for "filter_operation_info.field_type" in ' u'"has_edge_degree" filter: {}' . format ( filter_operation_info ) ) argument = parameters [ 0 ] if not is_variable_argument ( argument ) : raise GraphQLCompilationError ( u'The "has_edge_degree" filter only supports runtime ' u'variable arguments. Tagged values are not supported.' u'Argument name: {}' . format ( argument ) ) argument_inferred_type = GraphQLInt argument_expression , non_existence_expression = _represent_argument ( location , context , argument , argument_inferred_type ) if non_existence_expression is not None : raise AssertionError ( u'Since we do not support tagged values, non_existence_expression ' u'should have been None. However, it was: ' u'{}' . format ( non_existence_expression ) ) argument_is_zero = expressions . BinaryComposition ( u'=' , argument_expression , expressions . ZeroLiteral ) edge_field_is_null = expressions . BinaryComposition ( u'=' , expressions . LocalField ( filtered_field_name ) , expressions . NullLiteral ) edge_degree_is_zero = expressions . BinaryComposition ( u'&&' , argument_is_zero , edge_field_is_null ) edge_field_is_not_null = expressions . BinaryComposition ( u'!=' , expressions . LocalField ( filtered_field_name ) , expressions . NullLiteral ) edge_degree = expressions . UnaryTransformation ( u'size' , expressions . LocalField ( filtered_field_name ) ) edge_degree_matches_argument = expressions . BinaryComposition ( u'=' , edge_degree , argument_expression ) edge_degree_is_non_zero = expressions . BinaryComposition ( u'&&' , edge_field_is_not_null , edge_degree_matches_argument ) filter_predicate = expressions . BinaryComposition ( u'||' , edge_degree_is_zero , edge_degree_is_non_zero ) return blocks . Filter ( filter_predicate ) | 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 ( filtered_field_type ) ) current_type_fields = filtered_field_type . fields name_field = current_type_fields . get ( 'name' , None ) alias_field = current_type_fields . get ( 'alias' , None ) if not name_field or not alias_field : raise GraphQLCompilationError ( u'Cannot apply "name_or_alias" to type {} because it lacks a ' u'"name" or "alias" field.' . format ( filtered_field_type ) ) name_field_type = strip_non_null_from_type ( name_field . type ) alias_field_type = strip_non_null_from_type ( alias_field . type ) if not isinstance ( name_field_type , GraphQLScalarType ) : raise GraphQLCompilationError ( u'Cannot apply "name_or_alias" to type {} because its "name" ' u'field is not a scalar.' . format ( filtered_field_type ) ) if not isinstance ( alias_field_type , GraphQLList ) : raise GraphQLCompilationError ( u'Cannot apply "name_or_alias" to type {} because its ' u'"alias" field is not a list.' . format ( filtered_field_type ) ) alias_field_inner_type = strip_non_null_from_type ( alias_field_type . of_type ) if alias_field_inner_type != name_field_type : raise GraphQLCompilationError ( u'Cannot apply "name_or_alias" to type {} because the ' u'"name" field and the inner type of the "alias" field ' u'do not match: {} vs {}' . format ( filtered_field_type , name_field_type , alias_field_inner_type ) ) argument_inferred_type = name_field_type argument_expression , non_existence_expression = _represent_argument ( location , context , parameters [ 0 ] , argument_inferred_type ) check_against_name = expressions . BinaryComposition ( u'=' , expressions . LocalField ( 'name' ) , argument_expression ) check_against_alias = expressions . BinaryComposition ( u'contains' , expressions . LocalField ( 'alias' ) , argument_expression ) filter_predicate = expressions . BinaryComposition ( u'||' , check_against_name , check_against_alias ) if non_existence_expression is not None : filter_predicate = expressions . BinaryComposition ( u'||' , non_existence_expression , filter_predicate ) return blocks . Filter ( filter_predicate ) | 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_existence = _represent_argument ( location , context , parameters [ 0 ] , argument_inferred_type ) arg2_expression , arg2_non_existence = _represent_argument ( location , context , parameters [ 1 ] , argument_inferred_type ) lower_bound_clause = expressions . BinaryComposition ( u'>=' , expressions . LocalField ( filtered_field_name ) , arg1_expression ) if arg1_non_existence is not None : lower_bound_clause = expressions . BinaryComposition ( u'||' , arg1_non_existence , lower_bound_clause ) upper_bound_clause = expressions . BinaryComposition ( u'<=' , expressions . LocalField ( filtered_field_name ) , arg2_expression ) if arg2_non_existence is not None : upper_bound_clause = expressions . BinaryComposition ( u'||' , arg2_non_existence , upper_bound_clause ) filter_predicate = expressions . BinaryComposition ( u'&&' , lower_bound_clause , upper_bound_clause ) return blocks . Filter ( filter_predicate ) | 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_expression , non_existence_expression = _represent_argument ( location , context , parameters [ 0 ] , argument_inferred_type ) filter_predicate = expressions . BinaryComposition ( u'contains' , argument_expression , expressions . LocalField ( filtered_field_name ) ) if non_existence_expression is not None : filter_predicate = expressions . BinaryComposition ( u'||' , non_existence_expression , filter_predicate ) return blocks . Filter ( filter_predicate ) | 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 GraphQLCompilationError ( u'Cannot apply "has_substring" to non-string ' u'type {}' . format ( filtered_field_type ) ) argument_inferred_type = GraphQLString argument_expression , non_existence_expression = _represent_argument ( location , context , parameters [ 0 ] , argument_inferred_type ) filter_predicate = expressions . BinaryComposition ( u'has_substring' , expressions . LocalField ( filtered_field_name ) , argument_expression ) if non_existence_expression is not None : filter_predicate = expressions . BinaryComposition ( u'||' , non_existence_expression , filter_predicate ) return blocks . Filter ( filter_predicate ) | 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 , GraphQLList ) : raise GraphQLCompilationError ( u'Cannot apply "contains" to non-list ' u'type {}' . format ( filtered_field_type ) ) argument_inferred_type = strip_non_null_from_type ( base_field_type . of_type ) argument_expression , non_existence_expression = _represent_argument ( location , context , parameters [ 0 ] , argument_inferred_type ) filter_predicate = expressions . BinaryComposition ( u'contains' , expressions . LocalField ( filtered_field_name ) , argument_expression ) if non_existence_expression is not None : filter_predicate = expressions . BinaryComposition ( u'||' , non_existence_expression , filter_predicate ) return blocks . Filter ( filter_predicate ) | 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_inferred_type , GraphQLList ) : raise GraphQLCompilationError ( u'Cannot apply "intersects" to non-list ' u'type {}' . format ( filtered_field_type ) ) argument_expression , non_existence_expression = _represent_argument ( location , context , parameters [ 0 ] , argument_inferred_type ) filter_predicate = expressions . BinaryComposition ( u'intersects' , expressions . LocalField ( filtered_field_name ) , argument_expression ) if non_existence_expression is not None : filter_predicate = expressions . BinaryComposition ( u'||' , non_existence_expression , filter_predicate ) return blocks . Filter ( filter_predicate ) | 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_collection' : _process_in_collection_filter_directive , u'has_substring' : _process_has_substring_filter_directive , u'contains' : _process_contains_filter_directive , u'intersects' : _process_intersects_filter_directive , u'has_edge_degree' : _process_has_edge_degree_filter_directive , } all_recognized_filters = frozenset ( non_comparison_filters . keys ( ) ) | COMPARISON_OPERATORS if all_recognized_filters != ALL_OPERATORS : unrecognized_filters = ALL_OPERATORS - all_recognized_filters raise AssertionError ( u'Some filtering operators are defined but do not have an associated ' u'processing function. This is a bug: {}' . format ( unrecognized_filters ) ) if op_name in COMPARISON_OPERATORS : process_func = partial ( _process_comparison_filter_directive , operator = op_name ) else : process_func = non_comparison_filters . get ( op_name , None ) if process_func is None : raise GraphQLCompilationError ( u'Unknown op_name for filter directive: {}' . format ( op_name ) ) if ( filter_operation_info . field_name is None and op_name not in INNER_SCOPE_VERTEX_FIELD_OPERATORS ) : raise GraphQLCompilationError ( u'The filter with op_name "{}" must be applied on a field. ' u'It may not be applied on a type coercion.' . format ( op_name ) ) fields = ( ( filter_operation_info . field_name , ) if op_name != 'name_or_alias' else ( 'name' , 'alias' ) ) context [ 'metadata' ] . record_filter_info ( location , FilterInfo ( fields = fields , op_name = op_name , args = tuple ( operator_params ) ) ) return process_func ( filter_operation_info , location , context , operator_params ) | 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 [ query_path ] return location_info . type . name | 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 , selectable . original , [ col . name for col in selectable . c ] , context ) ) return column | 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 unexpectedly applied twice in the same ' u'location: {} {}' . format ( directive_name , ast . directives ) ) else : result [ directive_name ] = directive_obj return result | 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 ( directive_obj ) : if not is_vertex_field_type ( current_schema_type ) : raise GraphQLCompilationError ( u'Found disallowed filter on a property field: {} {} ' u'{}' . format ( directive_obj , current_schema_type , filtered_field_name ) ) elif isinstance ( ast , InlineFragment ) : raise GraphQLCompilationError ( u'Found disallowed filter on a type coercion: {} ' u'{}' . format ( directive_obj , current_schema_type ) ) else : pass else : operation = FilterOperationInfo ( directive = directive_obj , field_name = filtered_field_name , field_type = current_schema_type , field_ast = ast ) result . append ( operation ) if inner_vertex_fields : for inner_ast in inner_vertex_fields : for directive_obj in inner_ast . directives : if is_filter_with_outer_scope_vertex_field_operator ( directive_obj ) : filtered_field_name = get_ast_field_name ( inner_ast ) filtered_field_type = get_vertex_field_type ( current_schema_type , filtered_field_name ) operation = FilterOperationInfo ( directive = directive_obj , field_name = filtered_field_name , field_type = filtered_field_type , field_ast = inner_ast ) result . append ( operation ) return result | 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 operator that is not' u'allowed on the root vertex: {}' . format ( directive_obj ) ) directives_present_at_root . add ( directive_name ) disallowed_directives = directives_present_at_root & VERTEX_DIRECTIVES_PROHIBITED_ON_ROOT if disallowed_directives : raise GraphQLCompilationError ( u'Found prohibited directives on root vertex: ' u'{}' . format ( disallowed_directives ) ) | 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 . get ( 'recurse' , None ) if fold_directive and optional_directive : raise GraphQLCompilationError ( u'@fold and @optional may not appear at the same ' u'vertex field! Parent location: {}, vertex field name: {}' . format ( parent_location , vertex_field_name ) ) if fold_directive and output_source_directive : raise GraphQLCompilationError ( u'@fold and @output_source may not appear at the same ' u'vertex field! Parent location: {}, vertex field name: {}' . format ( parent_location , vertex_field_name ) ) if fold_directive and recurse_directive : raise GraphQLCompilationError ( u'@fold and @recurse may not appear at the same ' u'vertex field! Parent location: {}, vertex field name: {}' . format ( parent_location , vertex_field_name ) ) if optional_directive and output_source_directive : raise GraphQLCompilationError ( u'@optional and @output_source may not appear at the same ' u'vertex field! Parent location: {}, vertex field name: {}' . format ( parent_location , vertex_field_name ) ) if optional_directive and recurse_directive : raise GraphQLCompilationError ( u'@optional and @recurse may not appear at the same ' u'vertex field! Parent location: {}, vertex field name: {}' . format ( parent_location , vertex_field_name ) ) | 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 . get ( 'output_source' , None ) fold_context = 'fold' in context optional_context = 'optional' in context output_source_context = 'output_source' in context if fold_directive and fold_context : raise GraphQLCompilationError ( u'@fold is not allowed within a @fold traversal! ' u'Parent location: {}, vertex field name: {}' . format ( parent_location , vertex_field_name ) ) if optional_directive and fold_context : raise GraphQLCompilationError ( u'@optional is not allowed within a @fold traversal! ' u'Parent location: {}, vertex field name: {}' . format ( parent_location , vertex_field_name ) ) if output_source_directive and fold_context : raise GraphQLCompilationError ( u'@output_source is not allowed within a @fold traversal! ' u'Parent location: {}, vertex field name: {}' . format ( parent_location , vertex_field_name ) ) if recurse_directive and fold_context : raise GraphQLCompilationError ( u'@recurse is not allowed within a @fold traversal! ' u'Parent location: {}, vertex field name: {}' . format ( parent_location , vertex_field_name ) ) if output_source_context and not fold_directive : raise GraphQLCompilationError ( u'Found non-fold vertex field after the vertex marked ' u'output source! Parent location: {}, vertex field name: {}' . format ( parent_location , vertex_field_name ) ) if optional_context and fold_directive : raise GraphQLCompilationError ( u'@fold is not allowed within a @optional traversal! ' u'Parent location: {}, vertex field name: {}' . format ( parent_location , vertex_field_name ) ) if optional_context and output_source_directive : raise GraphQLCompilationError ( u'@output_source is not allowed within a @optional ' u'traversal! Parent location: {}, vertex field name: {}' . format ( parent_location , vertex_field_name ) ) | 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_types , value_type , value ) ) try : serialized_value = graphql_type . serialize ( value ) except ValueError as e : raise GraphQLInvalidArgumentError ( e ) return _safe_match_string ( serialized_value ) | 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 ) ) if not isinstance ( argument_value , list ) : raise GraphQLInvalidArgumentError ( u'Attempting to represent a non-list as a list: ' u'{}' . format ( argument_value ) ) components = ( _safe_match_argument ( stripped_type , x ) for x in argument_value ) return u'[' + u',' . join ( components ) + u']' | 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 sanitized_arguments = { key : _safe_match_argument ( argument_types [ key ] , value ) for key , value in six . iteritems ( arguments ) } return base_query . format ( ** sanitized_arguments ) | 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_tuple [ 1 : ] : if isinstance ( block , CoerceType ) : if coerce_type_block is not None : raise AssertionError ( u'Unexpectedly found two blocks eligible for "class" clause: ' u'{} {} {}' . format ( block , coerce_type_block , ir_tuple ) ) coerce_type_block = block elif isinstance ( block , MarkLocation ) : if as_block is not None : raise AssertionError ( u'Unexpectedly found two blocks eligible for "as" clause: ' u'{} {} {}' . format ( block , as_block , ir_tuple ) ) as_block = block elif isinstance ( block , Filter ) : if where_block is not None : raise AssertionError ( u'Unexpectedly found two blocks eligible for "where" clause: ' u'{} {} {}' . format ( block , as_block , ir_tuple ) ) if as_block is not None : raise AssertionError ( u'Unexpectedly found MarkLocation before Filter in ' u'MatchStep: {} {} {}' . format ( block , where_block , ir_tuple ) ) where_block = block else : raise AssertionError ( u'Unexpected block encountered: {} {}' . format ( block , ir_tuple ) ) step = MatchStep ( root_block = root_block , coerce_type_block = coerce_type_block , where_block = where_block , as_block = as_block ) if isinstance ( root_block , Backtrack ) : if where_block is not None or coerce_type_block is not None : raise AssertionError ( u'Unexpected blocks in Backtrack-based MatchStep: {}' . format ( step ) ) return step | 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 isinstance ( block , ( CoerceType , Filter , MarkLocation ) ) : current_tuple += ( block , ) else : raise AssertionError ( u'Unexpected block type when converting to MATCH query: ' u'{} {}' . format ( block , pruned_ir_blocks ) ) if current_tuple is None : raise AssertionError ( u'current_tuple was unexpectedly None: {}' . format ( pruned_ir_blocks ) ) output . append ( current_tuple ) return [ _per_location_tuple_to_step ( x ) for x in output ] | 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 : raise AssertionError ( u'current_list was unexpectedly None: {}' . format ( match_steps ) ) output . append ( current_list ) return output | 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_output_and_folds = extract_folds_from_ir_blocks ( ir_except_output ) global_operation_ir_blocks_tuple = _extract_global_operations ( ir_except_output_and_folds ) global_operation_blocks , pruned_ir_blocks = global_operation_ir_blocks_tuple if len ( global_operation_blocks ) > 1 : raise AssertionError ( u'Received IR blocks with multiple global operation blocks. Only one ' u'is allowed: {} {}' . format ( global_operation_blocks , ir_blocks ) ) if len ( global_operation_blocks ) == 1 : if not isinstance ( global_operation_blocks [ 0 ] , Filter ) : raise AssertionError ( u'Received non-Filter global operation block. {}' . format ( global_operation_blocks [ 0 ] ) ) where_block = global_operation_blocks [ 0 ] else : where_block = None match_steps = _split_ir_into_match_steps ( pruned_ir_blocks ) match_traversals = _split_match_steps_into_match_traversals ( match_steps ) return MatchQuery ( match_traversals = match_traversals , folds = folds , output_block = output_block , where_block = where_block , ) | 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 AssertionError ( u'Non-Expression object {} found in expression_list' . format ( expression_list [ 0 ] ) ) if len ( expression_list ) == 1 : return expression_list [ 0 ] else : return BinaryComposition ( u'&&' , expression_list_to_conjunction ( expression_list [ 1 : ] ) , expression_list [ 0 ] ) | 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_field' ] optional_edge_location = root_location . navigate_to_field ( edge_field ) optional_edge_where_filter = _filter_orientdb_simple_optional_edge ( query_metadata_table , optional_edge_location , inner_location_name ) inner_location_name_to_where_filter [ inner_location_name ] = optional_edge_where_filter where_filter_expressions = [ inner_location_name_to_where_filter [ key ] for key in sorted ( inner_location_name_to_where_filter . keys ( ) ) ] return expression_list_to_conjunction ( where_filter_expressions ) | 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: {} {}' . format ( type ( self . lower_bound ) . __name__ , self . lower_bound ) ) if not isinstance ( self . upper_bound , Expression ) : raise TypeError ( u'Expected Expression upper_bound, got: {} {}' . format ( type ( self . upper_bound ) . __name__ , self . upper_bound ) ) | 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 locations are present. This should not happen: {}' . format ( optional_root_location , optional_root_locations_path ) ) if optional_root_location not in self . _location_to_children : encountered_simple_optional = True else : self . _location_to_children [ parent_location ] . add ( optional_root_location ) parent_location = optional_root_location | 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_tree . query_path_to_filters , query_path_to_node = sql_query_tree . query_path_to_node , compiler_metadata = compiler_metadata , ) return _query_tree_to_query ( sql_query_tree . root , context ) | 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 ) . where ( and_ ( * filters ) ) return query | 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 ) columns . append ( column ) return columns | 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_binary_composition_to_expression , } expression_type = type ( expression ) if expression_type not in _expression_transformers : raise NotImplementedError ( u'Unsupported compiler expression "{}" of type "{}" cannot be converted to SQL ' u'expression.' . format ( expression , type ( expression ) ) ) return _expression_transformers [ expression_type ] ( expression , node , context ) | 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_OPERATORS [ expression . operator ] left = _expression_to_sql ( expression . left , node , context ) right = _expression_to_sql ( expression . right , node , context ) if sql_operator . cardinality == constants . CARDINALITY_UNARY : left , right = _get_column_and_bindparam ( left , right , sql_operator ) clause = getattr ( left , sql_operator . name ) ( right ) return clause elif sql_operator . cardinality == constants . CARDINALITY_BINARY : clause = getattr ( sql_expressions , sql_operator . name ) ( left , right ) return clause elif sql_operator . cardinality == constants . CARDINALITY_LIST_VALUED : left , right = _get_column_and_bindparam ( left , right , sql_operator ) right . expanding = True clause = getattr ( left , sql_operator . name ) ( right ) return clause raise AssertionError ( u'Unreachable, operator cardinality {} for compiler expression {} is ' u'unknown' . format ( sql_operator . cardinality , expression ) ) | 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 [ 1 : ] ) | 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'!=' , ContextField ( expression . location , location_type ) , NullLiteral ) def construct_result_visitor_fn ( expression ) : if not isinstance ( expression , ContextFieldExistence ) : return expression location_type = query_metadata_table . get_location_info ( expression . location ) . type return BinaryComposition ( u'!=' , OutputContextVertex ( expression . location , location_type ) , NullLiteral ) new_ir_blocks = [ ] for block in ir_blocks : new_block = None if isinstance ( block , ConstructResult ) : new_block = block . visit_and_update_expressions ( construct_result_visitor_fn ) else : new_block = block . visit_and_update_expressions ( regular_visitor_fn ) new_ir_blocks . append ( new_block ) return new_ir_blocks | 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_composition = isinstance ( expression . right , BinaryComposition ) if not left_is_binary_composition and not right_is_binary_composition : return expression identity_literal = None inverse_literal = None if expression . operator == u'=' : identity_literal = TrueLiteral inverse_literal = FalseLiteral elif expression . operator == u'!=' : identity_literal = FalseLiteral inverse_literal = TrueLiteral else : return expression expression_to_rewrite = None if expression . left == identity_literal and right_is_binary_composition : return expression . right elif expression . right == identity_literal and left_is_binary_composition : return expression . left elif expression . left == inverse_literal and right_is_binary_composition : expression_to_rewrite = expression . right elif expression . right == inverse_literal and left_is_binary_composition : expression_to_rewrite = expression . left if expression_to_rewrite is None : return expression elif expression_to_rewrite . operator not in operator_inverses : return expression else : return BinaryComposition ( operator_inverses [ expression_to_rewrite . operator ] , expression_to_rewrite . left , expression_to_rewrite . right ) new_ir_blocks = [ ] for block in ir_blocks : new_block = block . visit_and_update_expressions ( visitor_fn ) new_ir_blocks . append ( new_block ) return new_ir_blocks | 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_roots ) } ) simple_optional_root_to_inner_location = { optional_root_location : inner_location for inner_location , optional_root_location in location_to_preceding_optional_root_iteritems if optional_root_location not in complex_optional_roots } simple_optional_root_locations = set ( simple_optional_root_to_inner_location . keys ( ) ) _ , non_folded_ir_blocks = extract_folds_from_ir_blocks ( ir_blocks ) simple_optional_root_info = { } preceding_location = None for current_block in non_folded_ir_blocks : if isinstance ( current_block , MarkLocation ) : preceding_location = current_block . location elif isinstance ( current_block , Traverse ) and current_block . optional : if preceding_location in simple_optional_root_locations : inner_location = simple_optional_root_to_inner_location [ preceding_location ] inner_location_name , _ = inner_location . get_location_name ( ) simple_optional_info_dict = { 'inner_location_name' : inner_location_name , 'edge_field' : current_block . get_field_name ( ) , } simple_optional_root_info [ preceding_location ] = simple_optional_info_dict return simple_optional_root_info | 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 ( '%' ) , BinaryComposition ( u'+' , expression . right , Literal ( '%' ) ) ) ) new_ir_blocks = [ block . visit_and_update_expressions ( visitor_fn ) for block in ir_blocks ] return new_ir_blocks | 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 is None : raise AssertionError ( u'Unexpectedly found a single-step traversal with no as_block:' u' {} {}' . format ( current_match_traversal , match_query ) ) if single_step . as_block . location in visited_locations : ignore_traversal = True if not ignore_traversal : for step in current_match_traversal : if step . as_block is not None : visited_locations . add ( step . as_block . location ) new_match_traversals . append ( current_match_traversal ) return match_query . _replace ( match_traversals = new_match_traversals ) | 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 ( destination ) final_destination = _update_translation ( destination ) location_translations [ source ] = final_destination return final_destination while sources_to_process : _update_translation ( sources_to_process . pop ( ) ) | 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 , old_location ) if expression . location . field is not None : new_location = new_location . navigate_to_field ( expression . location . field ) expression_cls = type ( expression ) return expression_cls ( new_location , expression . field_type ) elif isinstance ( expression , ContextFieldExistence ) : old_location = expression . location new_location = location_translations . get ( old_location , old_location ) return ContextFieldExistence ( new_location ) elif isinstance ( expression , FoldedContextField ) : old_location = expression . fold_scope_location . base_location new_location = location_translations . get ( old_location , old_location ) fold_path = expression . fold_scope_location . fold_path fold_field = expression . fold_scope_location . field new_fold_scope_location = FoldScopeLocation ( new_location , fold_path , field = fold_field ) field_type = expression . field_type return FoldedContextField ( new_fold_scope_location , field_type ) else : return expression for current_match_traversal in match_query . match_traversals : new_traversal = [ ] for step in current_match_traversal : new_step = step if isinstance ( new_step . root_block , Backtrack ) : old_location = new_step . root_block . location if old_location in location_translations : new_location = location_translations [ old_location ] new_step = new_step . _replace ( root_block = Backtrack ( new_location ) ) if new_step . as_block is not None : old_location = new_step . as_block . location if old_location in location_translations : new_location = location_translations [ old_location ] new_step = new_step . _replace ( as_block = MarkLocation ( new_location ) ) if new_step . where_block is not None : new_where_block = new_step . where_block . visit_and_update_expressions ( visitor_fn ) new_step = new_step . _replace ( where_block = new_where_block ) new_traversal . append ( new_step ) new_match_traversals . append ( new_traversal ) new_folds = { } for fold_scope_location , fold_ir_blocks in six . iteritems ( match_query . folds ) : fold_path = fold_scope_location . fold_path fold_field = fold_scope_location . field old_location = fold_scope_location . base_location new_location = location_translations . get ( old_location , old_location ) new_fold_scope_location = FoldScopeLocation ( new_location , fold_path , field = fold_field ) new_folds [ new_fold_scope_location ] = fold_ir_blocks new_output_block = match_query . output_block . visit_and_update_expressions ( visitor_fn ) new_where_block = None if match_query . where_block is not None : new_where_block = match_query . where_block . visit_and_update_expressions ( visitor_fn ) return match_query . _replace ( match_traversals = new_match_traversals , folds = new_folds , output_block = new_output_block , where_block = new_where_block ) | 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_ir_blocks | 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_query . _replace ( match_queries = lowered_match_queries ) | 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 . as_block . location optional_root_locations_stack = location_to_optional_roots . get ( current_location , None ) optional_root_location = optional_root_locations_stack [ - 1 ] if optional_root_location is None : raise AssertionError ( u'Found optional Traverse location {} that was not present ' u'in location_to_optional_roots dict: {}' . format ( current_location , location_to_optional_roots ) ) elif optional_root_location in omitted_locations : field_name = step . root_block . get_field_name ( ) new_predicate = filter_edge_field_non_existence ( LocalField ( field_name ) ) old_filter = new_match_traversal [ - 1 ] . where_block if old_filter is not None : new_predicate = BinaryComposition ( u'&&' , old_filter . predicate , new_predicate ) new_match_step = new_match_traversal [ - 1 ] . _replace ( where_block = Filter ( new_predicate ) ) new_match_traversal [ - 1 ] = new_match_step new_step = None elif optional_root_location in complex_optional_roots : new_root_block = Traverse ( step . root_block . direction , step . root_block . edge_name ) new_step = step . _replace ( root_block = new_root_block ) else : pass if new_step is None : break else : new_match_traversal . append ( new_step ) return new_match_traversal | 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_location_subsets = [ set ( complex_optional_roots ) - set ( subset ) for subset in rooted_optional_root_location_subsets ] sorted_omitted_location_subsets = sorted ( omitted_location_subsets ) compound_match_traversals = [ ] for omitted_locations in reversed ( sorted_omitted_location_subsets ) : new_match_traversals = [ ] for match_traversal in match_query . match_traversals : location = match_traversal [ 0 ] . as_block . location optional_root_locations_stack = location_to_optional_roots . get ( location , None ) if optional_root_locations_stack is not None : optional_root_location = optional_root_locations_stack [ - 1 ] else : optional_root_location = None if optional_root_location is None or optional_root_location not in omitted_locations : new_match_traversal = _prune_traverse_using_omitted_locations ( match_traversal , set ( omitted_locations ) , complex_optional_roots , location_to_optional_roots ) new_match_traversals . append ( new_match_traversal ) else : pass compound_match_traversals . append ( new_match_traversals ) match_queries = [ MatchQuery ( match_traversals = match_traversals , folds = match_query . folds , output_block = match_query . output_block , where_block = match_query . where_block , ) for match_traversals in compound_match_traversals ] return CompoundMatchQuery ( match_queries = match_queries ) | 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 ( location_name ) if isinstance ( step . root_block , Traverse ) and not step . root_block . optional : present_non_optional_locations . add ( location_name ) if not present_non_optional_locations . issubset ( present_locations ) : raise AssertionError ( u'present_non_optional_locations {} was not a subset of ' u'present_locations {}. THis hould never happen.' . format ( present_non_optional_locations , present_locations ) ) return present_locations , present_non_optional_locations | 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 = [ ] for match_query in compound_match_query . match_queries : match_traversals = match_query . match_traversals output_block = match_query . output_block present_locations_tuple = _get_present_locations ( match_traversals ) present_locations , present_non_optional_locations = present_locations_tuple new_output_fields = { } for output_name , expression in six . iteritems ( output_block . fields ) : if isinstance ( expression , OutputContextField ) : location_name , _ = expression . location . get_location_name ( ) if location_name not in present_locations : raise AssertionError ( u'Non-optional output location {} was not found in ' u'present_locations: {}' . format ( expression . location , present_locations ) ) new_output_fields [ output_name ] = expression elif isinstance ( expression , FoldedContextField ) : base_location = expression . fold_scope_location . base_location location_name , _ = base_location . get_location_name ( ) if location_name not in present_locations : raise AssertionError ( u'Folded output location {} was found in ' u'present_locations: {}' . format ( base_location , present_locations ) ) new_output_fields [ output_name ] = expression elif isinstance ( expression , TernaryConditional ) : location_name , _ = expression . if_true . location . get_location_name ( ) if location_name in present_locations : if location_name in present_non_optional_locations : new_output_fields [ output_name ] = expression . if_true else : new_output_fields [ output_name ] = expression else : raise AssertionError ( u'Invalid expression of type {} in output block: ' u'{}' . format ( type ( expression ) . __name__ , output_block ) ) match_queries . append ( MatchQuery ( match_traversals = match_traversals , folds = match_query . folds , output_block = ConstructResult ( new_output_fields ) , where_block = match_query . where_block , ) ) return CompoundMatchQuery ( match_queries = 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 . setdefault ( current_location , [ ] ) . append ( current_filter ) return 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 Filter objects. Received: {}' . format ( filter_list ) ) expression_list = [ filter_block . predicate for filter_block in filter_list ] return expression_list_to_conjunction ( expression_list ) | 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 : raise AssertionError ( u'The same location {} was encountered twice in a single ' u'match traversal: {}. This should never happen.' . format ( current_location , match_traversal ) ) if all ( ( current_location in location_to_filters , current_location not in already_filtered_locations ) ) : where_block = Filter ( _filter_list_to_conjunction_expression ( location_to_filters [ current_location ] ) ) newly_filtered_locations . add ( current_location ) else : where_block = None new_match_step = MatchStep ( root_block = match_step . root_block , coerce_type_block = match_step . coerce_type_block , where_block = where_block , as_block = match_step . as_block ) new_match_traversal . append ( new_match_step ) return new_match_traversal , 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 match_query . match_traversals : result = _apply_filters_to_first_location_occurrence ( match_traversal , location_to_filters , already_filtered_locations ) new_match_traversal , newly_filtered_locations = result new_match_traversals . append ( new_match_traversal ) already_filtered_locations . update ( newly_filtered_locations ) new_match_queries . append ( MatchQuery ( match_traversals = new_match_traversals , folds = match_query . folds , output_block = match_query . output_block , where_block = match_query . where_block , ) ) return CompoundMatchQuery ( match_queries = new_match_queries ) | 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 happen.' . format ( expression ) ) if isinstance ( expression . left , ContextField ) : context_field = expression . left location_name , _ = context_field . location . get_location_name ( ) if location_name not in present_locations : return TrueLiteral if isinstance ( expression . right , ContextField ) : context_field = expression . right location_name , _ = context_field . location . get_location_name ( ) if location_name not in present_locations : return TrueLiteral return expression | 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 ( expression ) ) if expression . operator == u'||' : if expression . left == TrueLiteral or expression . right == TrueLiteral : return TrueLiteral else : return expression elif expression . operator == u'&&' : if expression . left == TrueLiteral : return expression . right if expression . right == TrueLiteral : return expression . left else : return expression else : return expression | 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 ) : return _update_context_field_binary_composition ( present_locations , expression ) else : return _simplify_non_context_field_binary_composition ( expression ) elif isinstance ( expression , TernaryConditional ) : return _simplify_ternary_conditional ( expression ) elif isinstance ( expression , BetweenClause ) : lower_bound = expression . lower_bound upper_bound = expression . upper_bound if isinstance ( lower_bound , ContextField ) or isinstance ( upper_bound , ContextField ) : raise AssertionError ( u'Found BetweenClause with ContextFields as lower/upper bounds. ' u'This should never happen: {}' . format ( expression ) ) return expression elif isinstance ( expression , ( OutputContextField , FoldedContextField ) ) : raise AssertionError ( u'Found unexpected expression of type {}. This should never happen: ' u'{}' . format ( type ( expression ) . __name__ , expression ) ) elif isinstance ( expression , no_op_blocks ) : return expression raise AssertionError ( u'Found unhandled expression of type {}. This should never happen: ' u'{}' . format ( type ( expression ) . __name__ , expression ) ) | 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 ) if new_filter . predicate == TrueLiteral : new_filter = None new_step = step . _replace ( where_block = new_filter ) else : new_step = step new_match_traversal . append ( new_step ) new_match_traversals . append ( new_match_traversal ) return new_match_traversals | 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_query else : new_match_queries = [ ] for match_query in compound_match_query . match_queries : match_traversals = match_query . match_traversals present_locations , _ = _get_present_locations ( match_traversals ) current_visitor_fn = partial ( _update_context_field_expression , present_locations ) new_match_traversals = _lower_non_existent_context_field_filters ( match_traversals , current_visitor_fn ) new_match_queries . append ( MatchQuery ( match_traversals = new_match_traversals , folds = match_query . folds , output_block = match_query . output_block , where_block = match_query . where_block , ) ) return CompoundMatchQuery ( match_queries = new_match_queries ) | 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 IllegalSchemaStateError ( u'Edge class "{}" has a property of type Link that is ' u'not an edge endpoint, this is not allowed: ' u'{}' . format ( class_name , property_name ) ) | 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.' . format ( class_name , property_name ) ) | 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_SOURCE_PROPERTY_NAME , None ) result . pop ( EDGE_DESTINATION_PROPERTY_NAME , None ) return result | 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 if non_existent_properties : raise InvalidPropertyError ( u'Class "{}" does not have definitions for properties "{}": ' u'{}' . format ( classname , non_existent_properties , property_names ) ) | 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 : raise AssertionError ( u'Class {} appears to be both a vertex and an edge class: ' u'{}' . format ( class_name , inheritance_set ) ) elif is_vertex : self . _vertex_class_names . add ( class_name ) elif is_edge : self . _edge_class_names . add ( class_name ) else : self . _non_graph_class_names . add ( class_name ) self . _vertex_class_names = frozenset ( self . _vertex_class_names ) self . _edge_class_names = frozenset ( self . _edge_class_names ) self . _non_graph_class_names = frozenset ( self . _non_graph_class_names ) | Assign each class to the vertex edge or non - graph type sets based on its kind . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.