id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
51
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
246,800
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
make_type_replacement_visitor
def make_type_replacement_visitor(find_types, replacement_func): """Return a visitor function that replaces expressions of a given type with new expressions.""" def visitor_fn(expression): """Return a replacement expression if the original expression is of the correct type.""" if isinstance(expr...
python
def make_type_replacement_visitor(find_types, replacement_func): def visitor_fn(expression): """Return a replacement expression if the original expression is of the correct type.""" if isinstance(expression, find_types): return replacement_func(expression) else: retur...
[ "def", "make_type_replacement_visitor", "(", "find_types", ",", "replacement_func", ")", ":", "def", "visitor_fn", "(", "expression", ")", ":", "\"\"\"Return a replacement expression if the original expression is of the correct type.\"\"\"", "if", "isinstance", "(", "expression",...
Return a visitor function that replaces expressions of a given type with new expressions.
[ "Return", "a", "visitor", "function", "that", "replaces", "expressions", "of", "a", "given", "type", "with", "new", "expressions", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L41-L50
246,801
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
_validate_operator_name
def _validate_operator_name(operator, supported_operators): """Ensure the named operator is valid and supported.""" if not isinstance(operator, six.text_type): raise TypeError(u'Expected operator as unicode string, got: {} {}'.format( type(operator).__name__, operator)) if operator not ...
python
def _validate_operator_name(operator, supported_operators): if not isinstance(operator, six.text_type): raise TypeError(u'Expected operator as unicode string, got: {} {}'.format( type(operator).__name__, operator)) if operator not in supported_operators: raise GraphQLCompilationErro...
[ "def", "_validate_operator_name", "(", "operator", ",", "supported_operators", ")", ":", "if", "not", "isinstance", "(", "operator", ",", "six", ".", "text_type", ")", ":", "raise", "TypeError", "(", "u'Expected operator as unicode string, got: {} {}'", ".", "format",...
Ensure the named operator is valid and supported.
[ "Ensure", "the", "named", "operator", "is", "valid", "and", "supported", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L665-L672
246,802
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
Literal.validate
def validate(self): """Validate that the Literal is correctly representable.""" # Literals representing boolean values or None are correctly representable and supported. if self.value is None or self.value is True or self.value is False: return # Literal safe strings are cor...
python
def validate(self): # Literals representing boolean values or None are correctly representable and supported. if self.value is None or self.value is True or self.value is False: return # Literal safe strings are correctly representable and supported. if isinstance(self.value...
[ "def", "validate", "(", "self", ")", ":", "# Literals representing boolean values or None are correctly representable and supported.", "if", "self", ".", "value", "is", "None", "or", "self", ".", "value", "is", "True", "or", "self", ".", "value", "is", "False", ":",...
Validate that the Literal is correctly representable.
[ "Validate", "that", "the", "Literal", "is", "correctly", "representable", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L72-L95
246,803
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
Variable.validate
def validate(self): """Validate that the Variable is correctly representable.""" # Get the first letter, or empty string if it doesn't exist. if not self.variable_name.startswith(u'$'): raise GraphQLCompilationError(u'Expected variable name to start with $, but was: ' ...
python
def validate(self): # Get the first letter, or empty string if it doesn't exist. if not self.variable_name.startswith(u'$'): raise GraphQLCompilationError(u'Expected variable name to start with $, but was: ' u'{}'.format(self.variable_name)) ...
[ "def", "validate", "(", "self", ")", ":", "# Get the first letter, or empty string if it doesn't exist.", "if", "not", "self", ".", "variable_name", ".", "startswith", "(", "u'$'", ")", ":", "raise", "GraphQLCompilationError", "(", "u'Expected variable name to start with $,...
Validate that the Variable is correctly representable.
[ "Validate", "that", "the", "Variable", "is", "correctly", "representable", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L154-L183
246,804
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
Variable.to_match
def to_match(self): """Return a unicode object with the MATCH representation of this Variable.""" self.validate() # We don't want the dollar sign as part of the variable name. variable_with_no_dollar_sign = self.variable_name[1:] match_variable_name = '{%s}' % (six.text_type(va...
python
def to_match(self): self.validate() # We don't want the dollar sign as part of the variable name. variable_with_no_dollar_sign = self.variable_name[1:] match_variable_name = '{%s}' % (six.text_type(variable_with_no_dollar_sign),) # We can't directly pass a Date or DateTime obj...
[ "def", "to_match", "(", "self", ")", ":", "self", ".", "validate", "(", ")", "# We don't want the dollar sign as part of the variable name.", "variable_with_no_dollar_sign", "=", "self", ".", "variable_name", "[", "1", ":", "]", "match_variable_name", "=", "'{%s}'", "...
Return a unicode object with the MATCH representation of this Variable.
[ "Return", "a", "unicode", "object", "with", "the", "MATCH", "representation", "of", "this", "Variable", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L185-L204
246,805
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
GlobalContextField.validate
def validate(self): """Validate that the GlobalContextField is correctly representable.""" if not isinstance(self.location, Location): raise TypeError(u'Expected Location location, got: {} {}' .format(type(self.location).__name__, self.location)) if self....
python
def validate(self): if not isinstance(self.location, Location): raise TypeError(u'Expected Location location, got: {} {}' .format(type(self.location).__name__, self.location)) if self.location.field is None: raise AssertionError(u'Received Location wi...
[ "def", "validate", "(", "self", ")", ":", "if", "not", "isinstance", "(", "self", ".", "location", ",", "Location", ")", ":", "raise", "TypeError", "(", "u'Expected Location location, got: {} {}'", ".", "format", "(", "type", "(", "self", ".", "location", ")...
Validate that the GlobalContextField is correctly representable.
[ "Validate", "that", "the", "GlobalContextField", "is", "correctly", "representable", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L289-L300
246,806
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
GlobalContextField.to_match
def to_match(self): """Return a unicode object with the MATCH representation of this GlobalContextField.""" self.validate() mark_name, field_name = self.location.get_location_name() validate_safe_string(mark_name) validate_safe_string(field_name) return u'%s.%s' % (mark...
python
def to_match(self): self.validate() mark_name, field_name = self.location.get_location_name() validate_safe_string(mark_name) validate_safe_string(field_name) return u'%s.%s' % (mark_name, field_name)
[ "def", "to_match", "(", "self", ")", ":", "self", ".", "validate", "(", ")", "mark_name", ",", "field_name", "=", "self", ".", "location", ".", "get_location_name", "(", ")", "validate_safe_string", "(", "mark_name", ")", "validate_safe_string", "(", "field_na...
Return a unicode object with the MATCH representation of this GlobalContextField.
[ "Return", "a", "unicode", "object", "with", "the", "MATCH", "representation", "of", "this", "GlobalContextField", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L302-L310
246,807
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
ContextField.to_match
def to_match(self): """Return a unicode object with the MATCH representation of this ContextField.""" self.validate() mark_name, field_name = self.location.get_location_name() validate_safe_string(mark_name) if field_name is None: return u'$matched.%s' % (mark_name,...
python
def to_match(self): self.validate() mark_name, field_name = self.location.get_location_name() validate_safe_string(mark_name) if field_name is None: return u'$matched.%s' % (mark_name,) else: validate_safe_string(field_name) return u'$matched...
[ "def", "to_match", "(", "self", ")", ":", "self", ".", "validate", "(", ")", "mark_name", ",", "field_name", "=", "self", ".", "location", ".", "get_location_name", "(", ")", "validate_safe_string", "(", "mark_name", ")", "if", "field_name", "is", "None", ...
Return a unicode object with the MATCH representation of this ContextField.
[ "Return", "a", "unicode", "object", "with", "the", "MATCH", "representation", "of", "this", "ContextField", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L350-L361
246,808
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
OutputContextField.validate
def validate(self): """Validate that the OutputContextField is correctly representable.""" if not isinstance(self.location, Location): raise TypeError(u'Expected Location location, got: {} {}'.format( type(self.location).__name__, self.location)) if not self.location...
python
def validate(self): if not isinstance(self.location, Location): raise TypeError(u'Expected Location location, got: {} {}'.format( type(self.location).__name__, self.location)) if not self.location.field: raise ValueError(u'Expected Location object that points to ...
[ "def", "validate", "(", "self", ")", ":", "if", "not", "isinstance", "(", "self", ".", "location", ",", "Location", ")", ":", "raise", "TypeError", "(", "u'Expected Location location, got: {} {}'", ".", "format", "(", "type", "(", "self", ".", "location", ")...
Validate that the OutputContextField is correctly representable.
[ "Validate", "that", "the", "OutputContextField", "is", "correctly", "representable", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L404-L427
246,809
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
FoldedContextField.validate
def validate(self): """Validate that the FoldedContextField is correctly representable.""" if not isinstance(self.fold_scope_location, FoldScopeLocation): raise TypeError(u'Expected FoldScopeLocation fold_scope_location, got: {} {}'.format( type(self.fold_scope_location), sel...
python
def validate(self): if not isinstance(self.fold_scope_location, FoldScopeLocation): raise TypeError(u'Expected FoldScopeLocation fold_scope_location, got: {} {}'.format( type(self.fold_scope_location), self.fold_scope_location)) if self.fold_scope_location.field is None: ...
[ "def", "validate", "(", "self", ")", ":", "if", "not", "isinstance", "(", "self", ".", "fold_scope_location", ",", "FoldScopeLocation", ")", ":", "raise", "TypeError", "(", "u'Expected FoldScopeLocation fold_scope_location, got: {} {}'", ".", "format", "(", "type", ...
Validate that the FoldedContextField is correctly representable.
[ "Validate", "that", "the", "FoldedContextField", "is", "correctly", "representable", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L505-L530
246,810
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
FoldCountContextField.validate
def validate(self): """Validate that the FoldCountContextField is correctly representable.""" if not isinstance(self.fold_scope_location, FoldScopeLocation): raise TypeError(u'Expected FoldScopeLocation fold_scope_location, got: {} {}'.format( type(self.fold_scope_location), ...
python
def validate(self): if not isinstance(self.fold_scope_location, FoldScopeLocation): raise TypeError(u'Expected FoldScopeLocation fold_scope_location, got: {} {}'.format( type(self.fold_scope_location), self.fold_scope_location)) if self.fold_scope_location.field != COUNT_MET...
[ "def", "validate", "(", "self", ")", ":", "if", "not", "isinstance", "(", "self", ".", "fold_scope_location", ",", "FoldScopeLocation", ")", ":", "raise", "TypeError", "(", "u'Expected FoldScopeLocation fold_scope_location, got: {} {}'", ".", "format", "(", "type", ...
Validate that the FoldCountContextField is correctly representable.
[ "Validate", "that", "the", "FoldCountContextField", "is", "correctly", "representable", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L596-L605
246,811
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
ContextFieldExistence.validate
def validate(self): """Validate that the ContextFieldExistence is correctly representable.""" if not isinstance(self.location, Location): raise TypeError(u'Expected Location location, got: {} {}'.format( type(self.location).__name__, self.location)) if self.location....
python
def validate(self): if not isinstance(self.location, Location): raise TypeError(u'Expected Location location, got: {} {}'.format( type(self.location).__name__, self.location)) if self.location.field: raise ValueError(u'Expected location to point to a vertex, ' ...
[ "def", "validate", "(", "self", ")", ":", "if", "not", "isinstance", "(", "self", ".", "location", ",", "Location", ")", ":", "raise", "TypeError", "(", "u'Expected Location location, got: {} {}'", ".", "format", "(", "type", "(", "self", ".", "location", ")...
Validate that the ContextFieldExistence is correctly representable.
[ "Validate", "that", "the", "ContextFieldExistence", "is", "correctly", "representable", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L646-L654
246,812
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
UnaryTransformation.validate
def validate(self): """Validate that the UnaryTransformation is correctly representable.""" _validate_operator_name(self.operator, UnaryTransformation.SUPPORTED_OPERATORS) if not isinstance(self.inner_expression, Expression): raise TypeError(u'Expected Expression inner_expression, g...
python
def validate(self): _validate_operator_name(self.operator, UnaryTransformation.SUPPORTED_OPERATORS) if not isinstance(self.inner_expression, Expression): raise TypeError(u'Expected Expression inner_expression, got {} {}'.format( type(self.inner_expression).__name__, self.inn...
[ "def", "validate", "(", "self", ")", ":", "_validate_operator_name", "(", "self", ".", "operator", ",", "UnaryTransformation", ".", "SUPPORTED_OPERATORS", ")", "if", "not", "isinstance", "(", "self", ".", "inner_expression", ",", "Expression", ")", ":", "raise",...
Validate that the UnaryTransformation is correctly representable.
[ "Validate", "that", "the", "UnaryTransformation", "is", "correctly", "representable", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L688-L694
246,813
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
UnaryTransformation.to_match
def to_match(self): """Return a unicode object with the MATCH representation of this UnaryTransformation.""" self.validate() translation_table = { u'size': u'size()', } match_operator = translation_table.get(self.operator) if not match_operator: r...
python
def to_match(self): self.validate() translation_table = { u'size': u'size()', } match_operator = translation_table.get(self.operator) if not match_operator: raise AssertionError(u'Unrecognized operator used: ' u'{} {}'.for...
[ "def", "to_match", "(", "self", ")", ":", "self", ".", "validate", "(", ")", "translation_table", "=", "{", "u'size'", ":", "u'size()'", ",", "}", "match_operator", "=", "translation_table", ".", "get", "(", "self", ".", "operator", ")", "if", "not", "ma...
Return a unicode object with the MATCH representation of this UnaryTransformation.
[ "Return", "a", "unicode", "object", "with", "the", "MATCH", "representation", "of", "this", "UnaryTransformation", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L705-L722
246,814
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
BinaryComposition.validate
def validate(self): """Validate that the BinaryComposition is correctly representable.""" _validate_operator_name(self.operator, BinaryComposition.SUPPORTED_OPERATORS) if not isinstance(self.left, Expression): raise TypeError(u'Expected Expression left, got: {} {} {}'.format( ...
python
def validate(self): _validate_operator_name(self.operator, BinaryComposition.SUPPORTED_OPERATORS) if not isinstance(self.left, Expression): raise TypeError(u'Expected Expression left, got: {} {} {}'.format( type(self.left).__name__, self.left, self)) if not isinstan...
[ "def", "validate", "(", "self", ")", ":", "_validate_operator_name", "(", "self", ".", "operator", ",", "BinaryComposition", ".", "SUPPORTED_OPERATORS", ")", "if", "not", "isinstance", "(", "self", ".", "left", ",", "Expression", ")", ":", "raise", "TypeError"...
Validate that the BinaryComposition is correctly representable.
[ "Validate", "that", "the", "BinaryComposition", "is", "correctly", "representable", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L769-L779
246,815
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
BinaryComposition.to_match
def to_match(self): """Return a unicode object with the MATCH representation of this BinaryComposition.""" self.validate() # The MATCH versions of some operators require an inverted order of arguments. # pylint: disable=unused-variable regular_operator_format = '(%(left)s %(oper...
python
def to_match(self): self.validate() # The MATCH versions of some operators require an inverted order of arguments. # pylint: disable=unused-variable regular_operator_format = '(%(left)s %(operator)s %(right)s)' inverted_operator_format = '(%(right)s %(operator)s %(left)s)' # no...
[ "def", "to_match", "(", "self", ")", ":", "self", ".", "validate", "(", ")", "# The MATCH versions of some operators require an inverted order of arguments.", "# pylint: disable=unused-variable", "regular_operator_format", "=", "'(%(left)s %(operator)s %(right)s)'", "inverted_operato...
Return a unicode object with the MATCH representation of this BinaryComposition.
[ "Return", "a", "unicode", "object", "with", "the", "MATCH", "representation", "of", "this", "BinaryComposition", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L791-L836
246,816
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
TernaryConditional.validate
def validate(self): """Validate that the TernaryConditional is correctly representable.""" if not isinstance(self.predicate, Expression): raise TypeError(u'Expected Expression predicate, got: {} {}'.format( type(self.predicate).__name__, self.predicate)) if not isinst...
python
def validate(self): if not isinstance(self.predicate, Expression): raise TypeError(u'Expected Expression predicate, got: {} {}'.format( type(self.predicate).__name__, self.predicate)) if not isinstance(self.if_true, Expression): raise TypeError(u'Expected Expressi...
[ "def", "validate", "(", "self", ")", ":", "if", "not", "isinstance", "(", "self", ".", "predicate", ",", "Expression", ")", ":", "raise", "TypeError", "(", "u'Expected Expression predicate, got: {} {}'", ".", "format", "(", "type", "(", "self", ".", "predicate...
Validate that the TernaryConditional is correctly representable.
[ "Validate", "that", "the", "TernaryConditional", "is", "correctly", "representable", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L893-L903
246,817
kensho-technologies/graphql-compiler
graphql_compiler/compiler/expressions.py
TernaryConditional.to_match
def to_match(self): """Return a unicode object with the MATCH representation of this TernaryConditional.""" self.validate() # For MATCH, an additional validation step is needed -- we currently do not support # emitting MATCH code for TernaryConditional that contains another TernaryCondi...
python
def to_match(self): self.validate() # For MATCH, an additional validation step is needed -- we currently do not support # emitting MATCH code for TernaryConditional that contains another TernaryConditional # anywhere within the predicate expression. This is because the predicate express...
[ "def", "to_match", "(", "self", ")", ":", "self", ".", "validate", "(", ")", "# For MATCH, an additional validation step is needed -- we currently do not support", "# emitting MATCH code for TernaryConditional that contains another TernaryConditional", "# anywhere within the predicate expr...
Return a unicode object with the MATCH representation of this TernaryConditional.
[ "Return", "a", "unicode", "object", "with", "the", "MATCH", "representation", "of", "this", "TernaryConditional", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/expressions.py#L918-L945
246,818
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_sanity_checks.py
sanity_check_ir_blocks_from_frontend
def sanity_check_ir_blocks_from_frontend(ir_blocks, query_metadata_table): """Assert that IR blocks originating from the frontend do not have nonsensical structure. Args: ir_blocks: list of BasicBlocks representing the IR to sanity-check Raises: AssertionError, if the IR has unexpected str...
python
def sanity_check_ir_blocks_from_frontend(ir_blocks, query_metadata_table): if not ir_blocks: raise AssertionError(u'Received no ir_blocks: {}'.format(ir_blocks)) _sanity_check_fold_scope_locations_are_unique(ir_blocks) _sanity_check_no_nested_folds(ir_blocks) _sanity_check_query_root_block(ir_b...
[ "def", "sanity_check_ir_blocks_from_frontend", "(", "ir_blocks", ",", "query_metadata_table", ")", ":", "if", "not", "ir_blocks", ":", "raise", "AssertionError", "(", "u'Received no ir_blocks: {}'", ".", "format", "(", "ir_blocks", ")", ")", "_sanity_check_fold_scope_loca...
Assert that IR blocks originating from the frontend do not have nonsensical structure. Args: ir_blocks: list of BasicBlocks representing the IR to sanity-check Raises: AssertionError, if the IR has unexpected structure. If the IR produced by the front-end cannot be successfully and cor...
[ "Assert", "that", "IR", "blocks", "originating", "from", "the", "frontend", "do", "not", "have", "nonsensical", "structure", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_sanity_checks.py#L13-L36
246,819
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_sanity_checks.py
_sanity_check_registered_locations_parent_locations
def _sanity_check_registered_locations_parent_locations(query_metadata_table): """Assert that all registered locations' parent locations are also registered.""" for location, location_info in query_metadata_table.registered_locations: if (location != query_metadata_table.root_location and ...
python
def _sanity_check_registered_locations_parent_locations(query_metadata_table): for location, location_info in query_metadata_table.registered_locations: if (location != query_metadata_table.root_location and not query_metadata_table.root_location.is_revisited_at(location)): # If ...
[ "def", "_sanity_check_registered_locations_parent_locations", "(", "query_metadata_table", ")", ":", "for", "location", ",", "location_info", "in", "query_metadata_table", ".", "registered_locations", ":", "if", "(", "location", "!=", "query_metadata_table", ".", "root_loca...
Assert that all registered locations' parent locations are also registered.
[ "Assert", "that", "all", "registered", "locations", "parent", "locations", "are", "also", "registered", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_sanity_checks.py#L39-L54
246,820
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_sanity_checks.py
_sanity_check_all_marked_locations_are_registered
def _sanity_check_all_marked_locations_are_registered(ir_blocks, query_metadata_table): """Assert that all locations in MarkLocation blocks have registered and valid metadata.""" # Grab all the registered locations, then make sure that: # - Any location that appears in a MarkLocation block is also registere...
python
def _sanity_check_all_marked_locations_are_registered(ir_blocks, query_metadata_table): # Grab all the registered locations, then make sure that: # - Any location that appears in a MarkLocation block is also registered. # - There are no registered locations that do not appear in a MarkLocation block. re...
[ "def", "_sanity_check_all_marked_locations_are_registered", "(", "ir_blocks", ",", "query_metadata_table", ")", ":", "# Grab all the registered locations, then make sure that:", "# - Any location that appears in a MarkLocation block is also registered.", "# - There are no registered locations th...
Assert that all locations in MarkLocation blocks have registered and valid metadata.
[ "Assert", "that", "all", "locations", "in", "MarkLocation", "blocks", "have", "registered", "and", "valid", "metadata", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_sanity_checks.py#L57-L80
246,821
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_sanity_checks.py
_sanity_check_fold_scope_locations_are_unique
def _sanity_check_fold_scope_locations_are_unique(ir_blocks): """Assert that every FoldScopeLocation that exists on a Fold block is unique.""" observed_locations = dict() for block in ir_blocks: if isinstance(block, Fold): alternate = observed_locations.get(block.fold_scope_location, Non...
python
def _sanity_check_fold_scope_locations_are_unique(ir_blocks): observed_locations = dict() for block in ir_blocks: if isinstance(block, Fold): alternate = observed_locations.get(block.fold_scope_location, None) if alternate is not None: raise AssertionError(u'Found...
[ "def", "_sanity_check_fold_scope_locations_are_unique", "(", "ir_blocks", ")", ":", "observed_locations", "=", "dict", "(", ")", "for", "block", "in", "ir_blocks", ":", "if", "isinstance", "(", "block", ",", "Fold", ")", ":", "alternate", "=", "observed_locations"...
Assert that every FoldScopeLocation that exists on a Fold block is unique.
[ "Assert", "that", "every", "FoldScopeLocation", "that", "exists", "on", "a", "Fold", "block", "is", "unique", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_sanity_checks.py#L83-L92
246,822
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_sanity_checks.py
_sanity_check_no_nested_folds
def _sanity_check_no_nested_folds(ir_blocks): """Assert that there are no nested Fold contexts, and that every Fold has a matching Unfold.""" fold_seen = False for block in ir_blocks: if isinstance(block, Fold): if fold_seen: raise AssertionError(u'Found a nested Fold con...
python
def _sanity_check_no_nested_folds(ir_blocks): fold_seen = False for block in ir_blocks: if isinstance(block, Fold): if fold_seen: raise AssertionError(u'Found a nested Fold contexts: {}'.format(ir_blocks)) else: fold_seen = True elif isinst...
[ "def", "_sanity_check_no_nested_folds", "(", "ir_blocks", ")", ":", "fold_seen", "=", "False", "for", "block", "in", "ir_blocks", ":", "if", "isinstance", "(", "block", ",", "Fold", ")", ":", "if", "fold_seen", ":", "raise", "AssertionError", "(", "u'Found a n...
Assert that there are no nested Fold contexts, and that every Fold has a matching Unfold.
[ "Assert", "that", "there", "are", "no", "nested", "Fold", "contexts", "and", "that", "every", "Fold", "has", "a", "matching", "Unfold", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_sanity_checks.py#L95-L109
246,823
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_sanity_checks.py
_sanity_check_query_root_block
def _sanity_check_query_root_block(ir_blocks): """Assert that QueryRoot is always the first block, and only the first block.""" if not isinstance(ir_blocks[0], QueryRoot): raise AssertionError(u'The first block was not QueryRoot: {}'.format(ir_blocks)) for block in ir_blocks[1:]: if isinstan...
python
def _sanity_check_query_root_block(ir_blocks): if not isinstance(ir_blocks[0], QueryRoot): raise AssertionError(u'The first block was not QueryRoot: {}'.format(ir_blocks)) for block in ir_blocks[1:]: if isinstance(block, QueryRoot): raise AssertionError(u'Found QueryRoot after the fi...
[ "def", "_sanity_check_query_root_block", "(", "ir_blocks", ")", ":", "if", "not", "isinstance", "(", "ir_blocks", "[", "0", "]", ",", "QueryRoot", ")", ":", "raise", "AssertionError", "(", "u'The first block was not QueryRoot: {}'", ".", "format", "(", "ir_blocks", ...
Assert that QueryRoot is always the first block, and only the first block.
[ "Assert", "that", "QueryRoot", "is", "always", "the", "first", "block", "and", "only", "the", "first", "block", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_sanity_checks.py#L112-L118
246,824
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_sanity_checks.py
_sanity_check_construct_result_block
def _sanity_check_construct_result_block(ir_blocks): """Assert that ConstructResult is always the last block, and only the last block.""" if not isinstance(ir_blocks[-1], ConstructResult): raise AssertionError(u'The last block was not ConstructResult: {}'.format(ir_blocks)) for block in ir_blocks[:-...
python
def _sanity_check_construct_result_block(ir_blocks): if not isinstance(ir_blocks[-1], ConstructResult): raise AssertionError(u'The last block was not ConstructResult: {}'.format(ir_blocks)) for block in ir_blocks[:-1]: if isinstance(block, ConstructResult): raise AssertionError(u'Fou...
[ "def", "_sanity_check_construct_result_block", "(", "ir_blocks", ")", ":", "if", "not", "isinstance", "(", "ir_blocks", "[", "-", "1", "]", ",", "ConstructResult", ")", ":", "raise", "AssertionError", "(", "u'The last block was not ConstructResult: {}'", ".", "format"...
Assert that ConstructResult is always the last block, and only the last block.
[ "Assert", "that", "ConstructResult", "is", "always", "the", "last", "block", "and", "only", "the", "last", "block", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_sanity_checks.py#L121-L128
246,825
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_sanity_checks.py
_sanity_check_block_pairwise_constraints
def _sanity_check_block_pairwise_constraints(ir_blocks): """Assert that adjacent blocks obey all invariants.""" for first_block, second_block in pairwise(ir_blocks): # Always Filter before MarkLocation, never after. if isinstance(first_block, MarkLocation) and isinstance(second_block, Filter): ...
python
def _sanity_check_block_pairwise_constraints(ir_blocks): for first_block, second_block in pairwise(ir_blocks): # Always Filter before MarkLocation, never after. if isinstance(first_block, MarkLocation) and isinstance(second_block, Filter): raise AssertionError(u'Found Filter after MarkLo...
[ "def", "_sanity_check_block_pairwise_constraints", "(", "ir_blocks", ")", ":", "for", "first_block", ",", "second_block", "in", "pairwise", "(", "ir_blocks", ")", ":", "# Always Filter before MarkLocation, never after.", "if", "isinstance", "(", "first_block", ",", "MarkL...
Assert that adjacent blocks obey all invariants.
[ "Assert", "that", "adjacent", "blocks", "obey", "all", "invariants", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_sanity_checks.py#L144-L172
246,826
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_sanity_checks.py
_sanity_check_mark_location_preceding_optional_traverse
def _sanity_check_mark_location_preceding_optional_traverse(ir_blocks): """Assert that optional Traverse blocks are preceded by a MarkLocation.""" # Once all fold blocks are removed, each optional Traverse must have # a MarkLocation block immediately before it. _, new_ir_blocks = extract_folds_from_ir_b...
python
def _sanity_check_mark_location_preceding_optional_traverse(ir_blocks): # Once all fold blocks are removed, each optional Traverse must have # a MarkLocation block immediately before it. _, new_ir_blocks = extract_folds_from_ir_blocks(ir_blocks) for first_block, second_block in pairwise(new_ir_blocks): ...
[ "def", "_sanity_check_mark_location_preceding_optional_traverse", "(", "ir_blocks", ")", ":", "# Once all fold blocks are removed, each optional Traverse must have", "# a MarkLocation block immediately before it.", "_", ",", "new_ir_blocks", "=", "extract_folds_from_ir_blocks", "(", "ir_...
Assert that optional Traverse blocks are preceded by a MarkLocation.
[ "Assert", "that", "optional", "Traverse", "blocks", "are", "preceded", "by", "a", "MarkLocation", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_sanity_checks.py#L175-L185
246,827
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_sanity_checks.py
_sanity_check_every_location_is_marked
def _sanity_check_every_location_is_marked(ir_blocks): """Ensure that every new location is marked with a MarkLocation block.""" # Exactly one MarkLocation block is found between any block that starts an interval of blocks # that all affect the same query position, and the first subsequent block that affect...
python
def _sanity_check_every_location_is_marked(ir_blocks): # Exactly one MarkLocation block is found between any block that starts an interval of blocks # that all affect the same query position, and the first subsequent block that affects a # different position in the query. Such intervals include the followin...
[ "def", "_sanity_check_every_location_is_marked", "(", "ir_blocks", ")", ":", "# Exactly one MarkLocation block is found between any block that starts an interval of blocks", "# that all affect the same query position, and the first subsequent block that affects a", "# different position in the query...
Ensure that every new location is marked with a MarkLocation block.
[ "Ensure", "that", "every", "new", "location", "is", "marked", "with", "a", "MarkLocation", "block", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_sanity_checks.py#L188-L216
246,828
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_sanity_checks.py
_sanity_check_coerce_type_outside_of_fold
def _sanity_check_coerce_type_outside_of_fold(ir_blocks): """Ensure that CoerceType not in a @fold are followed by a MarkLocation or Filter block.""" is_in_fold = False for first_block, second_block in pairwise(ir_blocks): if isinstance(first_block, Fold): is_in_fold = True if n...
python
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_bloc...
[ "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", ")", ":", "i...
Ensure that CoerceType not in a @fold are followed by a MarkLocation or Filter block.
[ "Ensure", "that", "CoerceType", "not", "in", "a" ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_sanity_checks.py#L219-L232
246,829
kensho-technologies/graphql-compiler
graphql_compiler/schema_generation/schema_properties.py
validate_supported_property_type_id
def validate_supported_property_type_id(property_name, property_type_id): """Ensure that the given property type_id is supported by the graph.""" if property_type_id not in PROPERTY_TYPE_ID_TO_NAME: raise AssertionError(u'Property "{}" has unsupported property type id: ' u'{...
python
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))
[ "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'{}'", ".", ...
Ensure that the given property type_id is supported by the graph.
[ "Ensure", "that", "the", "given", "property", "type_id", "is", "supported", "by", "the", "graph", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/schema_generation/schema_properties.py#L96-L100
246,830
kensho-technologies/graphql-compiler
graphql_compiler/schema_generation/schema_properties.py
_parse_bool_default_value
def _parse_bool_default_value(property_name, default_value_string): """Parse and return the default value for a boolean property.""" lowercased_value_string = default_value_string.lower() if lowercased_value_string in {'0', 'false'}: return False elif lowercased_value_string in {'1', 'true'}: ...
python
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'Unsupporte...
[ "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", "F...
Parse and return the default value for a boolean property.
[ "Parse", "and", "return", "the", "default", "value", "for", "a", "boolean", "property", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/schema_generation/schema_properties.py#L103-L112
246,831
kensho-technologies/graphql-compiler
graphql_compiler/schema_generation/schema_properties.py
_parse_datetime_default_value
def _parse_datetime_default_value(property_name, default_value_string): """Parse and return the default value for a datetime property.""" # OrientDB doesn't use ISO-8601 datetime format, so we have to parse it manually # and then turn it into a python datetime object. strptime() will raise an exception ...
python
def _parse_datetime_default_value(property_name, default_value_string): # OrientDB doesn't use ISO-8601 datetime format, so we have to parse it manually # and then turn it into a python datetime object. strptime() will raise an exception # if the provided value cannot be parsed correctly. parsed_value =...
[ "def", "_parse_datetime_default_value", "(", "property_name", ",", "default_value_string", ")", ":", "# OrientDB doesn't use ISO-8601 datetime format, so we have to parse it manually", "# and then turn it into a python datetime object. strptime() will raise an exception", "# if the provided valu...
Parse and return the default value for a datetime property.
[ "Parse", "and", "return", "the", "default", "value", "for", "a", "datetime", "property", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/schema_generation/schema_properties.py#L115-L123
246,832
kensho-technologies/graphql-compiler
graphql_compiler/schema_generation/schema_properties.py
_parse_date_default_value
def _parse_date_default_value(property_name, default_value_string): """Parse and return the default value for a date property.""" # OrientDB doesn't use ISO-8601 datetime format, so we have to parse it manually # and then turn it into a python datetime object. strptime() will raise an exception # if the...
python
def _parse_date_default_value(property_name, default_value_string): # OrientDB doesn't use ISO-8601 datetime format, so we have to parse it manually # and then turn it into a python datetime object. strptime() will raise an exception # if the provided value cannot be parsed correctly. parsed_value = tim...
[ "def", "_parse_date_default_value", "(", "property_name", ",", "default_value_string", ")", ":", "# OrientDB doesn't use ISO-8601 datetime format, so we have to parse it manually", "# and then turn it into a python datetime object. strptime() will raise an exception", "# if the provided value ca...
Parse and return the default value for a date property.
[ "Parse", "and", "return", "the", "default", "value", "for", "a", "date", "property", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/schema_generation/schema_properties.py#L126-L132
246,833
kensho-technologies/graphql-compiler
graphql_compiler/schema_generation/schema_properties.py
parse_default_property_value
def parse_default_property_value(property_name, property_type_id, default_value_string): """Parse the default value string into its proper form given the property type ID. Args: property_name: string, the name of the property whose default value is being parsed. Used primarily to...
python
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() ...
[ "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", "(", ")", "el...
Parse the default value string into its proper form given the property type ID. Args: property_name: string, the name of the property whose default value is being parsed. Used primarily to construct meaningful error messages, should the default value prove inva...
[ "Parse", "the", "default", "value", "string", "into", "its", "proper", "form", "given", "the", "property", "type", "ID", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/schema_generation/schema_properties.py#L135-L171
246,834
kensho-technologies/graphql-compiler
graphql_compiler/compiler/common.py
_compile_graphql_generic
def _compile_graphql_generic(language, lowering_func, query_emitter_func, schema, graphql_string, type_equivalence_hints, compiler_metadata): """Compile the GraphQL input, lowering and emitting the query using the given functions. Args: language: string indicating the targe...
python
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...
[ "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", ",", "...
Compile the GraphQL input, lowering and emitting the query using the given functions. Args: language: string indicating the target language to compile to. lowering_func: Function to lower the compiler IR into a compatible form for the target language backend. query_em...
[ "Compile", "the", "GraphQL", "input", "lowering", "and", "emitting", "the", "query", "using", "the", "given", "functions", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/common.py#L122-L152
246,835
kensho-technologies/graphql-compiler
graphql_compiler/compiler/filters.py
scalar_leaf_only
def scalar_leaf_only(operator): """Ensure the filter function is only applied to scalar leaf types.""" def decorator(f): """Decorate the supplied function with the "scalar_leaf_only" logic.""" @wraps(f) def wrapper(filter_operation_info, context, parameters, *args, **kwargs): ...
python
def scalar_leaf_only(operator): def decorator(f): """Decorate the supplied function with the "scalar_leaf_only" logic.""" @wraps(f) def wrapper(filter_operation_info, context, parameters, *args, **kwargs): """Check that the type on which the operator operates is a scalar leaf typ...
[ "def", "scalar_leaf_only", "(", "operator", ")", ":", "def", "decorator", "(", "f", ")", ":", "\"\"\"Decorate the supplied function with the \"scalar_leaf_only\" logic.\"\"\"", "@", "wraps", "(", "f", ")", "def", "wrapper", "(", "filter_operation_info", ",", "context", ...
Ensure the filter function is only applied to scalar leaf types.
[ "Ensure", "the", "filter", "function", "is", "only", "applied", "to", "scalar", "leaf", "types", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/filters.py#L17-L37
246,836
kensho-technologies/graphql-compiler
graphql_compiler/compiler/filters.py
vertex_field_only
def vertex_field_only(operator): """Ensure the filter function is only applied to vertex field types.""" def decorator(f): """Decorate the supplied function with the "vertex_field_only" logic.""" @wraps(f) def wrapper(filter_operation_info, context, parameters, *args, **kwargs): ...
python
def vertex_field_only(operator): def decorator(f): """Decorate the supplied function with the "vertex_field_only" logic.""" @wraps(f) def wrapper(filter_operation_info, context, parameters, *args, **kwargs): """Check that the type on which the operator operates is a vertex field ...
[ "def", "vertex_field_only", "(", "operator", ")", ":", "def", "decorator", "(", "f", ")", ":", "\"\"\"Decorate the supplied function with the \"vertex_field_only\" logic.\"\"\"", "@", "wraps", "(", "f", ")", "def", "wrapper", "(", "filter_operation_info", ",", "context"...
Ensure the filter function is only applied to vertex field types.
[ "Ensure", "the", "filter", "function", "is", "only", "applied", "to", "vertex", "field", "types", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/filters.py#L40-L61
246,837
kensho-technologies/graphql-compiler
graphql_compiler/compiler/filters.py
takes_parameters
def takes_parameters(count): """Ensure the filter function has "count" parameters specified.""" def decorator(f): """Decorate the supplied function with the "takes_parameters" logic.""" @wraps(f) def wrapper(filter_operation_info, location, context, parameters, *args, **kwargs): ...
python
def takes_parameters(count): def decorator(f): """Decorate the supplied function with the "takes_parameters" logic.""" @wraps(f) def wrapper(filter_operation_info, location, context, parameters, *args, **kwargs): """Check that the supplied number of parameters equals the expected...
[ "def", "takes_parameters", "(", "count", ")", ":", "def", "decorator", "(", "f", ")", ":", "\"\"\"Decorate the supplied function with the \"takes_parameters\" logic.\"\"\"", "@", "wraps", "(", "f", ")", "def", "wrapper", "(", "filter_operation_info", ",", "location", ...
Ensure the filter function has "count" parameters specified.
[ "Ensure", "the", "filter", "function", "has", "count", "parameters", "specified", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/filters.py#L64-L79
246,838
kensho-technologies/graphql-compiler
graphql_compiler/compiler/filters.py
_represent_argument
def _represent_argument(directive_location, context, argument, inferred_type): """Return a two-element tuple that represents the argument to the directive being processed. Args: directive_location: Location where the directive is used. context: dict, various per-compilation data (e.g. declared ...
python
def _represent_argument(directive_location, context, argument, inferred_type): # Regardless of what kind of variable we are dealing with, # we want to ensure its name is valid. argument_name = argument[1:] validate_safe_string(argument_name) if is_variable_argument(argument): existing_type ...
[ "def", "_represent_argument", "(", "directive_location", ",", "context", ",", "argument", ",", "inferred_type", ")", ":", "# Regardless of what kind of variable we are dealing with,", "# we want to ensure its name is valid.", "argument_name", "=", "argument", "[", "1", ":", "...
Return a two-element tuple that represents the argument to the directive being processed. Args: directive_location: Location where the directive is used. context: dict, various per-compilation data (e.g. declared tags, whether the current block is optional, etc.). May be mutated in...
[ "Return", "a", "two", "-", "element", "tuple", "that", "represents", "the", "argument", "to", "the", "directive", "being", "processed", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/filters.py#L82-L156
246,839
kensho-technologies/graphql-compiler
graphql_compiler/compiler/filters.py
_process_comparison_filter_directive
def _process_comparison_filter_directive(filter_operation_info, location, context, parameters, operator=None): """Return a Filter basic block that performs the given comparison against the property field. Args: filter_operation_info: FilterOperationInfo object, ...
python
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 comparis...
[ "def", "_process_comparison_filter_directive", "(", "filter_operation_info", ",", "location", ",", "context", ",", "parameters", ",", "operator", "=", "None", ")", ":", "comparison_operators", "=", "{", "u'='", ",", "u'!='", ",", "u'>'", ",", "u'<'", ",", "u'>='...
Return a Filter basic block that performs the given comparison against the property field. Args: filter_operation_info: FilterOperationInfo object, containing the directive and field info of the field where the filter is to be applied. location: Location where this fi...
[ "Return", "a", "Filter", "basic", "block", "that", "performs", "the", "given", "comparison", "against", "the", "property", "field", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/filters.py#L161-L204
246,840
kensho-technologies/graphql-compiler
graphql_compiler/compiler/filters.py
_process_has_edge_degree_filter_directive
def _process_has_edge_degree_filter_directive(filter_operation_info, location, context, parameters): """Return a Filter basic block that checks the degree of the edge to the given vertex field. Args: filter_operation_info: FilterOperationInfo object, containing the directive and field info ...
python
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 ...
[ "def", "_process_has_edge_degree_filter_directive", "(", "filter_operation_info", ",", "location", ",", "context", ",", "parameters", ")", ":", "if", "isinstance", "(", "filter_operation_info", ".", "field_ast", ",", "InlineFragment", ")", ":", "raise", "AssertionError"...
Return a Filter basic block that checks the degree of the edge to the given vertex field. Args: filter_operation_info: FilterOperationInfo object, containing the directive and field info of the field where the filter is to be applied. location: Location where this fil...
[ "Return", "a", "Filter", "basic", "block", "that", "checks", "the", "degree", "of", "the", "edge", "to", "the", "given", "vertex", "field", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/filters.py#L209-L279
246,841
kensho-technologies/graphql-compiler
graphql_compiler/compiler/filters.py
_process_name_or_alias_filter_directive
def _process_name_or_alias_filter_directive(filter_operation_info, location, context, parameters): """Return a Filter basic block that checks for a match against an Entity's name or alias. Args: filter_operation_info: FilterOperationInfo object, containing the directive and field info ...
python
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 ' ...
[ "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", ",", "Grap...
Return a Filter basic block that checks for a match against an Entity's name or alias. Args: filter_operation_info: FilterOperationInfo object, containing the directive and field info of the field where the filter is to be applied. location: Location where this filter...
[ "Return", "a", "Filter", "basic", "block", "that", "checks", "for", "a", "match", "against", "an", "Entity", "s", "name", "or", "alias", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/filters.py#L284-L346
246,842
kensho-technologies/graphql-compiler
graphql_compiler/compiler/filters.py
_process_between_filter_directive
def _process_between_filter_directive(filter_operation_info, location, context, parameters): """Return a Filter basic block that checks that a field is between two values, inclusive. Args: filter_operation_info: FilterOperationInfo object, containing the directive and field info ...
python
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_exi...
[ "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_n...
Return a Filter basic block that checks that a field is between two values, inclusive. Args: filter_operation_info: FilterOperationInfo object, containing the directive and field info of the field where the filter is to be applied. location: Location where this filter...
[ "Return", "a", "Filter", "basic", "block", "that", "checks", "that", "a", "field", "is", "between", "two", "values", "inclusive", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/filters.py#L351-L392
246,843
kensho-technologies/graphql-compiler
graphql_compiler/compiler/filters.py
_process_in_collection_filter_directive
def _process_in_collection_filter_directive(filter_operation_info, location, context, parameters): """Return a Filter basic block that checks for a value's existence in a collection. Args: filter_operation_info: FilterOperationInfo object, containing the directive and field info ...
python
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...
[ "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", ".", "f...
Return a Filter basic block that checks for a value's existence in a collection. Args: filter_operation_info: FilterOperationInfo object, containing the directive and field info of the field where the filter is to be applied. location: Location where this filter is us...
[ "Return", "a", "Filter", "basic", "block", "that", "checks", "for", "a", "value", "s", "existence", "in", "a", "collection", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/filters.py#L397-L427
246,844
kensho-technologies/graphql-compiler
graphql_compiler/compiler/filters.py
_process_has_substring_filter_directive
def _process_has_substring_filter_directive(filter_operation_info, location, context, parameters): """Return a Filter basic block that checks if the directive arg is a substring of the field. Args: filter_operation_info: FilterOperationInfo object, containing the directive and field info ...
python
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 Gr...
[ "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", ".", "f...
Return a Filter basic block that checks if the directive arg is a substring of the field. Args: filter_operation_info: FilterOperationInfo object, containing the directive and field info of the field where the filter is to be applied. location: Location where this fil...
[ "Return", "a", "Filter", "basic", "block", "that", "checks", "if", "the", "directive", "arg", "is", "a", "substring", "of", "the", "field", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/filters.py#L432-L466
246,845
kensho-technologies/graphql-compiler
graphql_compiler/compiler/filters.py
_process_contains_filter_directive
def _process_contains_filter_directive(filter_operation_info, location, context, parameters): """Return a Filter basic block that checks if the directive arg is contained in the field. Args: filter_operation_info: FilterOperationInfo object, containing the directive and field info ...
python
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, ...
[ "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_...
Return a Filter basic block that checks if the directive arg is contained in the field. Args: filter_operation_info: FilterOperationInfo object, containing the directive and field info of the field where the filter is to be applied. location: Location where this filte...
[ "Return", "a", "Filter", "basic", "block", "that", "checks", "if", "the", "directive", "arg", "is", "contained", "in", "the", "field", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/filters.py#L470-L505
246,846
kensho-technologies/graphql-compiler
graphql_compiler/compiler/filters.py
_process_intersects_filter_directive
def _process_intersects_filter_directive(filter_operation_info, location, context, parameters): """Return a Filter basic block that checks if the directive arg and the field intersect. Args: filter_operation_info: FilterOperationInfo object, containing the directive and field info ...
python
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...
[ "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", ".", "fiel...
Return a Filter basic block that checks if the directive arg and the field intersect. Args: filter_operation_info: FilterOperationInfo object, containing the directive and field info of the field where the filter is to be applied. location: Location where this filter ...
[ "Return", "a", "Filter", "basic", "block", "that", "checks", "if", "the", "directive", "arg", "and", "the", "field", "intersect", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/filters.py#L509-L543
246,847
kensho-technologies/graphql-compiler
graphql_compiler/compiler/filters.py
is_filter_with_outer_scope_vertex_field_operator
def is_filter_with_outer_scope_vertex_field_operator(directive): """Return True if we have a filter directive whose operator applies to the outer scope.""" if directive.name.value != 'filter': return False op_name, _ = _get_filter_op_name_and_values(directive) return op_name in OUTER_SCOPE_VERT...
python
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
[ "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"...
Return True if we have a filter directive whose operator applies to the outer scope.
[ "Return", "True", "if", "we", "have", "a", "filter", "directive", "whose", "operator", "applies", "to", "the", "outer", "scope", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/filters.py#L598-L604
246,848
kensho-technologies/graphql-compiler
graphql_compiler/compiler/filters.py
process_filter_directive
def process_filter_directive(filter_operation_info, location, context): """Return a Filter basic block that corresponds to the filter operation in the directive. Args: filter_operation_info: FilterOperationInfo object, containing the directive and field info of the field ...
python
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,...
[ "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", "=", "{", ...
Return a Filter basic block that corresponds to the filter operation in the directive. Args: filter_operation_info: FilterOperationInfo object, containing the directive and field info of the field where the filter is to be applied. location: Location where this filter...
[ "Return", "a", "Filter", "basic", "block", "that", "corresponds", "to", "the", "filter", "operation", "in", "the", "directive", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/filters.py#L607-L663
246,849
kensho-technologies/graphql-compiler
graphql_compiler/compiler/sql_context_helpers.py
get_schema_type_name
def get_schema_type_name(node, context): """Return the GraphQL type name of a node.""" 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...
python
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...
[ "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 que...
Return the GraphQL type name of a node.
[ "Return", "the", "GraphQL", "type", "name", "of", "a", "node", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/sql_context_helpers.py#L5-L13
246,850
kensho-technologies/graphql-compiler
graphql_compiler/compiler/sql_context_helpers.py
get_node_at_path
def get_node_at_path(query_path, context): """Return the SqlNode associated with the query path.""" 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 = con...
python
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
[ "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...
Return the SqlNode associated with the query path.
[ "Return", "the", "SqlNode", "associated", "with", "the", "query", "path", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/sql_context_helpers.py#L27-L34
246,851
kensho-technologies/graphql-compiler
graphql_compiler/compiler/sql_context_helpers.py
try_get_column
def try_get_column(column_name, node, context): """Attempt to get a column by name from the selectable. Args: column_name: str, name of the column to retrieve. node: SqlNode, the node the column is being retrieved for. context: CompilationContext, compilation specific metadata. Ret...
python
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.ge...
[ "def", "try_get_column", "(", "column_name", ",", "node", ",", "context", ")", ":", "selectable", "=", "get_node_selectable", "(", "node", ",", "context", ")", "if", "not", "hasattr", "(", "selectable", ",", "'c'", ")", ":", "raise", "AssertionError", "(", ...
Attempt to get a column by name from the selectable. Args: column_name: str, name of the column to retrieve. node: SqlNode, the node the column is being retrieved for. context: CompilationContext, compilation specific metadata. Returns: Optional[column], the SQLAlchemy column i...
[ "Attempt", "to", "get", "a", "column", "by", "name", "from", "the", "selectable", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/sql_context_helpers.py#L37-L53
246,852
kensho-technologies/graphql-compiler
graphql_compiler/compiler/sql_context_helpers.py
get_column
def get_column(column_name, node, context): """Get a column by name from the selectable. Args: column_name: str, name of the column to retrieve. node: SqlNode, the node the column is being retrieved for. context: CompilationContext, compilation specific metadata. Returns: c...
python
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 {}.'...
[ "def", "get_column", "(", "column_name", ",", "node", ",", "context", ")", ":", "column", "=", "try_get_column", "(", "column_name", ",", "node", ",", "context", ")", "if", "column", "is", "None", ":", "selectable", "=", "get_node_selectable", "(", "node", ...
Get a column by name from the selectable. Args: column_name: str, name of the column to retrieve. node: SqlNode, the node the column is being retrieved for. context: CompilationContext, compilation specific metadata. Returns: column, the SQLAlchemy column if found. Raises an As...
[ "Get", "a", "column", "by", "name", "from", "the", "selectable", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/sql_context_helpers.py#L56-L74
246,853
kensho-technologies/graphql-compiler
graphql_compiler/compiler/directive_helpers.py
get_unique_directives
def get_unique_directives(ast): """Return a dict of directive name to directive object for the given AST node. Any directives that are allowed to exist more than once on any AST node are ignored. For any directives that can only exist up to once, we verify that they are not duplicated raising GraphQLCo...
python
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 # We don't return these. elif directive_n...
[ "def", "get_unique_directives", "(", "ast", ")", ":", "if", "not", "ast", ".", "directives", ":", "return", "dict", "(", ")", "result", "=", "dict", "(", ")", "for", "directive_obj", "in", "ast", ".", "directives", ":", "directive_name", "=", "directive_ob...
Return a dict of directive name to directive object for the given AST node. Any directives that are allowed to exist more than once on any AST node are ignored. For any directives that can only exist up to once, we verify that they are not duplicated raising GraphQLCompilationError in case we find them mor...
[ "Return", "a", "dict", "of", "directive", "name", "to", "directive", "object", "for", "the", "given", "AST", "node", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/directive_helpers.py#L27-L54
246,854
kensho-technologies/graphql-compiler
graphql_compiler/compiler/directive_helpers.py
get_local_filter_directives
def get_local_filter_directives(ast, current_schema_type, inner_vertex_fields): """Get all filter directives that apply to the current field. This helper abstracts away the fact that some vertex field filtering operators apply on the inner scope (the scope of the inner vertex field on which they are applie...
python
def get_local_filter_directives(ast, current_schema_type, inner_vertex_fields): result = [] if ast.directives: # it'll be None if the AST has no directives at that node for directive_obj in ast.directives: # Of all filters that appear *on the field itself*, only the ones that apply ...
[ "def", "get_local_filter_directives", "(", "ast", ",", "current_schema_type", ",", "inner_vertex_fields", ")", ":", "result", "=", "[", "]", "if", "ast", ".", "directives", ":", "# it'll be None if the AST has no directives at that node", "for", "directive_obj", "in", "...
Get all filter directives that apply to the current field. This helper abstracts away the fact that some vertex field filtering operators apply on the inner scope (the scope of the inner vertex field on which they are applied), whereas some apply on the outer scope (the scope that contains the inner vertex...
[ "Get", "all", "filter", "directives", "that", "apply", "to", "the", "current", "field", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/directive_helpers.py#L57-L121
246,855
kensho-technologies/graphql-compiler
graphql_compiler/compiler/directive_helpers.py
validate_property_directives
def validate_property_directives(directives): """Validate the directives that appear at a property field.""" for directive_name in six.iterkeys(directives): if directive_name in VERTEX_ONLY_DIRECTIVES: raise GraphQLCompilationError( u'Found vertex-only directive {} set on pro...
python
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))
[ "def", "validate_property_directives", "(", "directives", ")", ":", "for", "directive_name", "in", "six", ".", "iterkeys", "(", "directives", ")", ":", "if", "directive_name", "in", "VERTEX_ONLY_DIRECTIVES", ":", "raise", "GraphQLCompilationError", "(", "u'Found verte...
Validate the directives that appear at a property field.
[ "Validate", "the", "directives", "that", "appear", "at", "a", "property", "field", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/directive_helpers.py#L124-L129
246,856
kensho-technologies/graphql-compiler
graphql_compiler/compiler/directive_helpers.py
validate_vertex_directives
def validate_vertex_directives(directives): """Validate the directives that appear at a vertex field.""" for directive_name in six.iterkeys(directives): if directive_name in PROPERTY_ONLY_DIRECTIVES: raise GraphQLCompilationError( u'Found property-only directive {} set on ver...
python
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))
[ "def", "validate_vertex_directives", "(", "directives", ")", ":", "for", "directive_name", "in", "six", ".", "iterkeys", "(", "directives", ")", ":", "if", "directive_name", "in", "PROPERTY_ONLY_DIRECTIVES", ":", "raise", "GraphQLCompilationError", "(", "u'Found prope...
Validate the directives that appear at a vertex field.
[ "Validate", "the", "directives", "that", "appear", "at", "a", "vertex", "field", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/directive_helpers.py#L132-L137
246,857
kensho-technologies/graphql-compiler
graphql_compiler/compiler/directive_helpers.py
validate_root_vertex_directives
def validate_root_vertex_directives(root_ast): """Validate the directives that appear at the root vertex field.""" 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(direc...
python
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 di...
[ "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_...
Validate the directives that appear at the root vertex field.
[ "Validate", "the", "directives", "that", "appear", "at", "the", "root", "vertex", "field", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/directive_helpers.py#L140-L155
246,858
kensho-technologies/graphql-compiler
graphql_compiler/compiler/directive_helpers.py
validate_vertex_field_directive_interactions
def validate_vertex_field_directive_interactions(parent_location, vertex_field_name, directives): """Ensure that the specified vertex field directives are not mutually disallowed.""" fold_directive = directives.get('fold', None) optional_directive = directives.get('optional', None) output_source_directi...
python
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('recurs...
[ "def", "validate_vertex_field_directive_interactions", "(", "parent_location", ",", "vertex_field_name", ",", "directives", ")", ":", "fold_directive", "=", "directives", ".", "get", "(", "'fold'", ",", "None", ")", "optional_directive", "=", "directives", ".", "get",...
Ensure that the specified vertex field directives are not mutually disallowed.
[ "Ensure", "that", "the", "specified", "vertex", "field", "directives", "are", "not", "mutually", "disallowed", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/directive_helpers.py#L158-L188
246,859
kensho-technologies/graphql-compiler
graphql_compiler/compiler/directive_helpers.py
validate_vertex_field_directive_in_context
def validate_vertex_field_directive_in_context(parent_location, vertex_field_name, directives, context): """Ensure that the specified vertex field directives are allowed in the current context.""" fold_directive = directives.get('fold', None) optional_directive...
python
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) ...
[ "def", "validate_vertex_field_directive_in_context", "(", "parent_location", ",", "vertex_field_name", ",", "directives", ",", "context", ")", ":", "fold_directive", "=", "directives", ".", "get", "(", "'fold'", ",", "None", ")", "optional_directive", "=", "directives...
Ensure that the specified vertex field directives are allowed in the current context.
[ "Ensure", "that", "the", "specified", "vertex", "field", "directives", "are", "allowed", "in", "the", "current", "context", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/directive_helpers.py#L191-L231
246,860
kensho-technologies/graphql-compiler
graphql_compiler/query_formatting/match_formatting.py
_safe_match_string
def _safe_match_string(value): """Sanitize and represent a string argument in MATCH.""" if not isinstance(value, six.string_types): if isinstance(value, bytes): # should only happen in py3 value = value.decode('utf-8') else: raise GraphQLInvalidArgumentError(u'Attempting...
python
def _safe_match_string(value): if not isinstance(value, six.string_types): if isinstance(value, bytes): # should only happen in py3 value = value.decode('utf-8') else: raise GraphQLInvalidArgumentError(u'Attempting to convert a non-string into a string: ' ...
[ "def", "_safe_match_string", "(", "value", ")", ":", "if", "not", "isinstance", "(", "value", ",", "six", ".", "string_types", ")", ":", "if", "isinstance", "(", "value", ",", "bytes", ")", ":", "# should only happen in py3", "value", "=", "value", ".", "d...
Sanitize and represent a string argument in MATCH.
[ "Sanitize", "and", "represent", "a", "string", "argument", "in", "MATCH", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/query_formatting/match_formatting.py#L17-L29
246,861
kensho-technologies/graphql-compiler
graphql_compiler/query_formatting/match_formatting.py
_safe_match_date_and_datetime
def _safe_match_date_and_datetime(graphql_type, expected_python_types, value): """Represent date and datetime objects as MATCH strings.""" # Python datetime.datetime is a subclass of datetime.date, # but in this case, the two are not interchangeable. # Rather than using isinstance, we will therefore che...
python
def _safe_match_date_and_datetime(graphql_type, expected_python_types, value): # Python datetime.datetime is a subclass of datetime.date, # but in this case, the two are not interchangeable. # Rather than using isinstance, we will therefore check for exact type equality. value_type = type(value) if ...
[ "def", "_safe_match_date_and_datetime", "(", "graphql_type", ",", "expected_python_types", ",", "value", ")", ":", "# Python datetime.datetime is a subclass of datetime.date,", "# but in this case, the two are not interchangeable.", "# Rather than using isinstance, we will therefore check fo...
Represent date and datetime objects as MATCH strings.
[ "Represent", "date", "and", "datetime", "objects", "as", "MATCH", "strings", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/query_formatting/match_formatting.py#L32-L50
246,862
kensho-technologies/graphql-compiler
graphql_compiler/query_formatting/match_formatting.py
_safe_match_list
def _safe_match_list(inner_type, argument_value): """Represent the list of "inner_type" objects in MATCH form.""" stripped_type = strip_non_null_from_type(inner_type) if isinstance(stripped_type, GraphQLList): raise GraphQLInvalidArgumentError(u'MATCH does not currently support nested lists, ' ...
python
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 {}: ' ...
[ "def", "_safe_match_list", "(", "inner_type", ",", "argument_value", ")", ":", "stripped_type", "=", "strip_non_null_from_type", "(", "inner_type", ")", "if", "isinstance", "(", "stripped_type", ",", "GraphQLList", ")", ":", "raise", "GraphQLInvalidArgumentError", "("...
Represent the list of "inner_type" objects in MATCH form.
[ "Represent", "the", "list", "of", "inner_type", "objects", "in", "MATCH", "form", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/query_formatting/match_formatting.py#L59-L75
246,863
kensho-technologies/graphql-compiler
graphql_compiler/query_formatting/match_formatting.py
insert_arguments_into_match_query
def insert_arguments_into_match_query(compilation_result, arguments): """Insert the arguments into the compiled MATCH query to form a complete query. Args: compilation_result: a CompilationResult object derived from the GraphQL compiler arguments: dict, mapping argument name to its value, for e...
python
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 ...
[ "def", "insert_arguments_into_match_query", "(", "compilation_result", ",", "arguments", ")", ":", "if", "compilation_result", ".", "language", "!=", "MATCH_LANGUAGE", ":", "raise", "AssertionError", "(", "u'Unexpected query output language: {}'", ".", "format", "(", "com...
Insert the arguments into the compiled MATCH query to form a complete query. Args: compilation_result: a CompilationResult object derived from the GraphQL compiler arguments: dict, mapping argument name to its value, for every parameter the query expects. Returns: string, a MATCH query...
[ "Insert", "the", "arguments", "into", "the", "compiled", "MATCH", "query", "to", "form", "a", "complete", "query", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/query_formatting/match_formatting.py#L120-L142
246,864
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_sql/metadata.py
SqlMetadata.get_table
def get_table(self, schema_type): """Retrieve a SQLAlchemy table based on the supplied GraphQL schema type name.""" table_name = schema_type.lower() if not self.has_table(table_name): raise exceptions.GraphQLCompilationError( 'No Table found in SQLAlchemy metadata for...
python
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...
[ "def", "get_table", "(", "self", ",", "schema_type", ")", ":", "table_name", "=", "schema_type", ".", "lower", "(", ")", "if", "not", "self", ".", "has_table", "(", "table_name", ")", ":", "raise", "exceptions", ".", "GraphQLCompilationError", "(", "'No Tabl...
Retrieve a SQLAlchemy table based on the supplied GraphQL schema type name.
[ "Retrieve", "a", "SQLAlchemy", "table", "based", "on", "the", "supplied", "GraphQL", "schema", "type", "name", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_sql/metadata.py#L27-L34
246,865
kensho-technologies/graphql-compiler
graphql_compiler/compiler/match_query.py
_per_location_tuple_to_step
def _per_location_tuple_to_step(ir_tuple): """Construct a MatchStep from a tuple of its constituent blocks.""" root_block = ir_tuple[0] if not isinstance(root_block, root_block_types): raise AssertionError(u'Unexpected root block type for MatchStep: ' u'{} {}'.format(roo...
python
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...
[ "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:...
Construct a MatchStep from a tuple of its constituent blocks.
[ "Construct", "a", "MatchStep", "from", "a", "tuple", "of", "its", "constituent", "blocks", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/match_query.py#L39-L85
246,866
kensho-technologies/graphql-compiler
graphql_compiler/compiler/match_query.py
_split_ir_into_match_steps
def _split_ir_into_match_steps(pruned_ir_blocks): """Split a list of IR blocks into per-location MATCH steps. Args: pruned_ir_blocks: list of IR basic block objects that have gone through a lowering step. Returns: list of MatchStep namedtuples, each of which contains all basic blocks that ...
python
def _split_ir_into_match_steps(pruned_ir_blocks): output = [] current_tuple = None for block in pruned_ir_blocks: if isinstance(block, OutputSource): # OutputSource blocks do not require any MATCH code, and only serve to help # optimizations and debugging. Simply omit them at...
[ "def", "_split_ir_into_match_steps", "(", "pruned_ir_blocks", ")", ":", "output", "=", "[", "]", "current_tuple", "=", "None", "for", "block", "in", "pruned_ir_blocks", ":", "if", "isinstance", "(", "block", ",", "OutputSource", ")", ":", "# OutputSource blocks do...
Split a list of IR blocks into per-location MATCH steps. Args: pruned_ir_blocks: list of IR basic block objects that have gone through a lowering step. Returns: list of MatchStep namedtuples, each of which contains all basic blocks that correspond to a single MATCH step.
[ "Split", "a", "list", "of", "IR", "blocks", "into", "per", "-", "location", "MATCH", "steps", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/match_query.py#L88-L119
246,867
kensho-technologies/graphql-compiler
graphql_compiler/compiler/match_query.py
_split_match_steps_into_match_traversals
def _split_match_steps_into_match_traversals(match_steps): """Split a list of MatchSteps into multiple lists, each denoting a single MATCH traversal.""" output = [] current_list = None for step in match_steps: if isinstance(step.root_block, QueryRoot): if current_list is not None: ...
python
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: ...
[ "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"...
Split a list of MatchSteps into multiple lists, each denoting a single MATCH traversal.
[ "Split", "a", "list", "of", "MatchSteps", "into", "multiple", "lists", "each", "denoting", "a", "single", "MATCH", "traversal", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/match_query.py#L122-L138
246,868
kensho-technologies/graphql-compiler
graphql_compiler/compiler/match_query.py
convert_to_match_query
def convert_to_match_query(ir_blocks): """Convert the list of IR blocks into a MatchQuery object, for easier manipulation.""" output_block = ir_blocks[-1] if not isinstance(output_block, ConstructResult): raise AssertionError(u'Expected last IR block to be ConstructResult, found: ' ...
python
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]...
[ "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 Const...
Convert the list of IR blocks into a MatchQuery object, for easier manipulation.
[ "Convert", "the", "list", "of", "IR", "blocks", "into", "a", "MatchQuery", "object", "for", "easier", "manipulation", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/match_query.py#L178-L211
246,869
kensho-technologies/graphql-compiler
graphql_compiler/query_formatting/sql_formatting.py
insert_arguments_into_sql_query
def insert_arguments_into_sql_query(compilation_result, arguments): """Insert the arguments into the compiled SQL query to form a complete query. Args: compilation_result: CompilationResult, compilation result from the GraphQL compiler. arguments: Dict[str, Any], parameter name -> value, for ev...
python
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)
[ "def", "insert_arguments_into_sql_query", "(", "compilation_result", ",", "arguments", ")", ":", "if", "compilation_result", ".", "language", "!=", "SQL_LANGUAGE", ":", "raise", "AssertionError", "(", "u'Unexpected query output language: {}'", ".", "format", "(", "compila...
Insert the arguments into the compiled SQL query to form a complete query. Args: compilation_result: CompilationResult, compilation result from the GraphQL compiler. arguments: Dict[str, Any], parameter name -> value, for every parameter the query expects. Returns: SQLAlchemy Selectabl...
[ "Insert", "the", "arguments", "into", "the", "compiled", "SQL", "query", "to", "form", "a", "complete", "query", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/query_formatting/sql_formatting.py#L10-L23
246,870
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_match/utils.py
convert_coerce_type_to_instanceof_filter
def convert_coerce_type_to_instanceof_filter(coerce_type_block): """Create an "INSTANCEOF" Filter block from a CoerceType block.""" coerce_type_target = get_only_element_from_collection(coerce_type_block.target_class) # INSTANCEOF requires the target class to be passed in as a string, # so we make the ...
python
def convert_coerce_type_to_instanceof_filter(coerce_type_block): coerce_type_target = get_only_element_from_collection(coerce_type_block.target_class) # INSTANCEOF requires the target class to be passed in as a string, # so we make the target class a string literal. new_predicate = BinaryComposition( ...
[ "def", "convert_coerce_type_to_instanceof_filter", "(", "coerce_type_block", ")", ":", "coerce_type_target", "=", "get_only_element_from_collection", "(", "coerce_type_block", ".", "target_class", ")", "# INSTANCEOF requires the target class to be passed in as a string,", "# so we make...
Create an "INSTANCEOF" Filter block from a CoerceType block.
[ "Create", "an", "INSTANCEOF", "Filter", "block", "from", "a", "CoerceType", "block", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_match/utils.py#L15-L24
246,871
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_match/utils.py
convert_coerce_type_and_add_to_where_block
def convert_coerce_type_and_add_to_where_block(coerce_type_block, where_block): """Create an "INSTANCEOF" Filter from a CoerceType, adding to an existing Filter if any.""" instanceof_filter = convert_coerce_type_to_instanceof_filter(coerce_type_block) if where_block: # There was already a Filter bl...
python
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: # There was already a Filter block -- we'll merge the two predicates together. return Filter(BinaryComposition(u'&&', i...
[ "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", ":", "# There was already a Filter block -- we'll m...
Create an "INSTANCEOF" Filter from a CoerceType, adding to an existing Filter if any.
[ "Create", "an", "INSTANCEOF", "Filter", "from", "a", "CoerceType", "adding", "to", "an", "existing", "Filter", "if", "any", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_match/utils.py#L27-L35
246,872
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_match/utils.py
expression_list_to_conjunction
def expression_list_to_conjunction(expression_list): """Convert a list of expressions to an Expression that is the conjunction of all of them.""" if not isinstance(expression_list, list): raise AssertionError(u'Expected `list`, Received {}.'.format(expression_list)) if len(expression_list) == 0: ...
python
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 As...
[ "def", "expression_list_to_conjunction", "(", "expression_list", ")", ":", "if", "not", "isinstance", "(", "expression_list", ",", "list", ")", ":", "raise", "AssertionError", "(", "u'Expected `list`, Received {}.'", ".", "format", "(", "expression_list", ")", ")", ...
Convert a list of expressions to an Expression that is the conjunction of all of them.
[ "Convert", "a", "list", "of", "expressions", "to", "an", "Expression", "that", "is", "the", "conjunction", "of", "all", "of", "them", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_match/utils.py#L38-L54
246,873
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_match/utils.py
construct_where_filter_predicate
def construct_where_filter_predicate(query_metadata_table, simple_optional_root_info): """Return an Expression that is True if and only if each simple optional filter is True. Construct filters for each simple optional, that are True if and only if `edge_field` does not exist in the `simple_optional_root_l...
python
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['...
[ "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...
Return an Expression that is True if and only if each simple optional filter is True. Construct filters for each simple optional, that are True if and only if `edge_field` does not exist in the `simple_optional_root_location` OR the `inner_location` is not defined. Return an Expression that evaluates to Tr...
[ "Return", "an", "Expression", "that", "is", "True", "if", "and", "only", "if", "each", "simple", "optional", "filter", "is", "True", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_match/utils.py#L192-L233
246,874
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_match/utils.py
construct_optional_traversal_tree
def construct_optional_traversal_tree(complex_optional_roots, location_to_optional_roots): """Return a tree of complex optional root locations. Args: complex_optional_roots: list of @optional locations (location immmediately preceding an @optional Traverse) that expand v...
python
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
[ "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", "(", "lo...
Return a tree of complex optional root locations. Args: complex_optional_roots: list of @optional locations (location immmediately preceding an @optional Traverse) that expand vertex fields location_to_optional_roots: dict mapping from location -> optional_roots wher...
[ "Return", "a", "tree", "of", "complex", "optional", "root", "locations", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_match/utils.py#L337-L355
246,875
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_match/utils.py
BetweenClause.validate
def validate(self): """Validate that the Between Expression is correctly representable.""" 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...
python
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_bo...
[ "def", "validate", "(", "self", ")", ":", "if", "not", "isinstance", "(", "self", ".", "field", ",", "LocalField", ")", ":", "raise", "TypeError", "(", "u'Expected LocalField field, got: {} {}'", ".", "format", "(", "type", "(", "self", ".", "field", ")", ...
Validate that the Between Expression is correctly representable.
[ "Validate", "that", "the", "Between", "Expression", "is", "correctly", "representable", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_match/utils.py#L77-L89
246,876
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_match/utils.py
BetweenClause.to_match
def to_match(self): """Return a unicode object with the MATCH representation of this BetweenClause.""" 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(), ...
python
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())
[ "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", ...
Return a unicode object with the MATCH representation of this BetweenClause.
[ "Return", "a", "unicode", "object", "with", "the", "MATCH", "representation", "of", "this", "BetweenClause", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_match/utils.py#L101-L107
246,877
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_match/utils.py
OptionalTraversalTree.insert
def insert(self, optional_root_locations_path): """Insert a path of optional Locations into the tree. Each OptionalTraversalTree object contains child Location objects as keys mapping to other OptionalTraversalTree objects. Args: optional_root_locations_path: list of option...
python
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 roo...
[ "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_...
Insert a path of optional Locations into the tree. Each OptionalTraversalTree object contains child Location objects as keys mapping to other OptionalTraversalTree objects. Args: optional_root_locations_path: list of optional root Locations all except the last ...
[ "Insert", "a", "path", "of", "optional", "Locations", "into", "the", "tree", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_match/utils.py#L261-L285
246,878
kensho-technologies/graphql-compiler
graphql_compiler/compiler/emit_sql.py
emit_code_from_ir
def emit_code_from_ir(sql_query_tree, compiler_metadata): """Return a SQLAlchemy Query from a passed SqlQueryTree. Args: sql_query_tree: SqlQueryTree, tree representation of the query to emit. compiler_metadata: SqlMetadata, SQLAlchemy specific metadata. Returns: SQLAlchemy Query ...
python
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_filte...
[ "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_inf...
Return a SQLAlchemy Query from a passed SqlQueryTree. Args: sql_query_tree: SqlQueryTree, tree representation of the query to emit. compiler_metadata: SqlMetadata, SQLAlchemy specific metadata. Returns: SQLAlchemy Query
[ "Return", "a", "SQLAlchemy", "Query", "from", "a", "passed", "SqlQueryTree", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/emit_sql.py#L39-L58
246,879
kensho-technologies/graphql-compiler
graphql_compiler/compiler/emit_sql.py
_create_table_and_update_context
def _create_table_and_update_context(node, context): """Create an aliased table for a SqlNode. Updates the relevant Selectable global context. Args: node: SqlNode, the current node. context: CompilationContext, global compilation state and metadata. Returns: Table, the newly a...
python
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
[ "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", "(",...
Create an aliased table for a SqlNode. Updates the relevant Selectable global context. Args: node: SqlNode, the current node. context: CompilationContext, global compilation state and metadata. Returns: Table, the newly aliased SQLAlchemy table.
[ "Create", "an", "aliased", "table", "for", "a", "SqlNode", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/emit_sql.py#L75-L90
246,880
kensho-technologies/graphql-compiler
graphql_compiler/compiler/emit_sql.py
_create_query
def _create_query(node, context): """Create a query from a SqlNode. Args: node: SqlNode, the current node. context: CompilationContext, global compilation state and metadata. Returns: Selectable, selectable of the generated query. """ visited_nodes = [node] output_colum...
python
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_(*...
[ "def", "_create_query", "(", "node", ",", "context", ")", ":", "visited_nodes", "=", "[", "node", "]", "output_columns", "=", "_get_output_columns", "(", "visited_nodes", ",", "context", ")", "filters", "=", "_get_filters", "(", "visited_nodes", ",", "context", ...
Create a query from a SqlNode. Args: node: SqlNode, the current node. context: CompilationContext, global compilation state and metadata. Returns: Selectable, selectable of the generated query.
[ "Create", "a", "query", "from", "a", "SqlNode", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/emit_sql.py#L93-L108
246,881
kensho-technologies/graphql-compiler
graphql_compiler/compiler/emit_sql.py
_get_output_columns
def _get_output_columns(nodes, context): """Get the output columns for a list of SqlNodes. Args: nodes: List[SqlNode], the nodes to get output columns from. context: CompilationContext, global compilation state and metadata. Returns: List[Column], list of SqlAlchemy Columns to outp...
python
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_o...
[ "def", "_get_output_columns", "(", "nodes", ",", "context", ")", ":", "columns", "=", "[", "]", "for", "node", "in", "nodes", ":", "for", "sql_output", "in", "sql_context_helpers", ".", "get_outputs", "(", "node", ",", "context", ")", ":", "field_name", "=...
Get the output columns for a list of SqlNodes. Args: nodes: List[SqlNode], the nodes to get output columns from. context: CompilationContext, global compilation state and metadata. Returns: List[Column], list of SqlAlchemy Columns to output for this query.
[ "Get", "the", "output", "columns", "for", "a", "list", "of", "SqlNodes", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/emit_sql.py#L111-L128
246,882
kensho-technologies/graphql-compiler
graphql_compiler/compiler/emit_sql.py
_get_filters
def _get_filters(nodes, context): """Get filters to apply to a list of SqlNodes. Args: nodes: List[SqlNode], the SqlNodes to get filters for. context: CompilationContext, global compilation state and metadata. Returns: List[Expression], list of SQLAlchemy expressions. """ f...
python
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
[ "def", "_get_filters", "(", "nodes", ",", "context", ")", ":", "filters", "=", "[", "]", "for", "node", "in", "nodes", ":", "for", "filter_block", "in", "sql_context_helpers", ".", "get_filters", "(", "node", ",", "context", ")", ":", "filter_sql_expression"...
Get filters to apply to a list of SqlNodes. Args: nodes: List[SqlNode], the SqlNodes to get filters for. context: CompilationContext, global compilation state and metadata. Returns: List[Expression], list of SQLAlchemy expressions.
[ "Get", "filters", "to", "apply", "to", "a", "list", "of", "SqlNodes", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/emit_sql.py#L131-L146
246,883
kensho-technologies/graphql-compiler
graphql_compiler/compiler/emit_sql.py
_transform_filter_to_sql
def _transform_filter_to_sql(filter_block, node, context): """Transform a Filter block to its corresponding SQLAlchemy expression. Args: filter_block: Filter, the Filter block to transform. node: SqlNode, the node Filter block applies to. context: CompilationContext, global compilation ...
python
def _transform_filter_to_sql(filter_block, node, context): expression = filter_block.predicate return _expression_to_sql(expression, node, context)
[ "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. Args: filter_block: Filter, the Filter block to transform. node: SqlNode, the node Filter block applies to. context: CompilationContext, global compilation state and metadata. Returns: Expression, SQLAlchemy e...
[ "Transform", "a", "Filter", "block", "to", "its", "corresponding", "SQLAlchemy", "expression", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/emit_sql.py#L149-L161
246,884
kensho-technologies/graphql-compiler
graphql_compiler/compiler/emit_sql.py
_expression_to_sql
def _expression_to_sql(expression, node, context): """Recursively transform a Filter block predicate to its SQLAlchemy expression representation. Args: expression: expression, the compiler expression to transform. node: SqlNode, the SqlNode the expression applies to. context: Compilatio...
python
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:...
[ "def", "_expression_to_sql", "(", "expression", ",", "node", ",", "context", ")", ":", "_expression_transformers", "=", "{", "expressions", ".", "LocalField", ":", "_transform_local_field_to_expression", ",", "expressions", ".", "Variable", ":", "_transform_variable_to_...
Recursively transform a Filter block predicate to its SQLAlchemy expression representation. Args: expression: expression, the compiler expression to transform. node: SqlNode, the SqlNode the expression applies to. context: CompilationContext, global compilation state and metadata. Retu...
[ "Recursively", "transform", "a", "Filter", "block", "predicate", "to", "its", "SQLAlchemy", "expression", "representation", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/emit_sql.py#L164-L186
246,885
kensho-technologies/graphql-compiler
graphql_compiler/compiler/emit_sql.py
_transform_binary_composition_to_expression
def _transform_binary_composition_to_expression(expression, node, context): """Transform a BinaryComposition compiler expression into a SQLAlchemy expression. Recursively calls _expression_to_sql to convert its left and right sub-expressions. Args: expression: expression, BinaryComposition compile...
python
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 = const...
[ "def", "_transform_binary_composition_to_expression", "(", "expression", ",", "node", ",", "context", ")", ":", "if", "expression", ".", "operator", "not", "in", "constants", ".", "SUPPORTED_OPERATORS", ":", "raise", "NotImplementedError", "(", "u'Filter operation \"{}\...
Transform a BinaryComposition compiler expression into a SQLAlchemy expression. Recursively calls _expression_to_sql to convert its left and right sub-expressions. Args: expression: expression, BinaryComposition compiler expression. node: SqlNode, the SqlNode the expression applies to. ...
[ "Transform", "a", "BinaryComposition", "compiler", "expression", "into", "a", "SQLAlchemy", "expression", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/emit_sql.py#L189-L223
246,886
kensho-technologies/graphql-compiler
graphql_compiler/compiler/emit_sql.py
_transform_variable_to_expression
def _transform_variable_to_expression(expression, node, context): """Transform a Variable compiler expression into its SQLAlchemy expression representation. Args: expression: expression, Variable compiler expression. node: SqlNode, the SqlNode the expression applies to. context: Compila...
python
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)) retur...
[ "def", "_transform_variable_to_expression", "(", "expression", ",", "node", ",", "context", ")", ":", "variable_name", "=", "expression", ".", "variable_name", "if", "not", "variable_name", ".", "startswith", "(", "u'$'", ")", ":", "raise", "AssertionError", "(", ...
Transform a Variable compiler expression into its SQLAlchemy expression representation. Args: expression: expression, Variable compiler expression. node: SqlNode, the SqlNode the expression applies to. context: CompilationContext, global compilation state and metadata. Returns: ...
[ "Transform", "a", "Variable", "compiler", "expression", "into", "its", "SQLAlchemy", "expression", "representation", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/emit_sql.py#L255-L270
246,887
kensho-technologies/graphql-compiler
graphql_compiler/compiler/emit_sql.py
_transform_local_field_to_expression
def _transform_local_field_to_expression(expression, node, context): """Transform a LocalField compiler expression into its SQLAlchemy expression representation. Args: expression: expression, LocalField compiler expression. node: SqlNode, the SqlNode the expression applies to. context: ...
python
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
[ "def", "_transform_local_field_to_expression", "(", "expression", ",", "node", ",", "context", ")", ":", "column_name", "=", "expression", ".", "field_name", "column", "=", "sql_context_helpers", ".", "get_column", "(", "column_name", ",", "node", ",", "context", ...
Transform a LocalField compiler expression into its SQLAlchemy expression representation. Args: expression: expression, LocalField compiler expression. node: SqlNode, the SqlNode the expression applies to. context: CompilationContext, global compilation state and metadata. Returns: ...
[ "Transform", "a", "LocalField", "compiler", "expression", "into", "its", "SQLAlchemy", "expression", "representation", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/emit_sql.py#L273-L286
246,888
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_common.py
lower_context_field_existence
def lower_context_field_existence(ir_blocks, query_metadata_table): """Lower ContextFieldExistence expressions into lower-level expressions.""" def regular_visitor_fn(expression): """Expression visitor function that rewrites ContextFieldExistence expressions.""" if not isinstance(expression, Con...
python
def lower_context_field_existence(ir_blocks, query_metadata_table): def regular_visitor_fn(expression): """Expression visitor function that rewrites ContextFieldExistence expressions.""" if not isinstance(expression, ContextFieldExistence): return expression location_type = quer...
[ "def", "lower_context_field_existence", "(", "ir_blocks", ",", "query_metadata_table", ")", ":", "def", "regular_visitor_fn", "(", "expression", ")", ":", "\"\"\"Expression visitor function that rewrites ContextFieldExistence expressions.\"\"\"", "if", "not", "isinstance", "(", ...
Lower ContextFieldExistence expressions into lower-level expressions.
[ "Lower", "ContextFieldExistence", "expressions", "into", "lower", "-", "level", "expressions", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_common.py#L56-L95
246,889
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_common.py
optimize_boolean_expression_comparisons
def optimize_boolean_expression_comparisons(ir_blocks): """Optimize comparisons of a boolean binary comparison expression against a boolean literal. Rewriting example: BinaryComposition( '=', BinaryComposition('!=', something, NullLiteral) False) The above is re...
python
def optimize_boolean_expression_comparisons(ir_blocks): operator_inverses = { u'=': u'!=', u'!=': u'=', } def visitor_fn(expression): """Expression visitor function that performs the above rewriting.""" if not isinstance(expression, BinaryComposition): return exp...
[ "def", "optimize_boolean_expression_comparisons", "(", "ir_blocks", ")", ":", "operator_inverses", "=", "{", "u'='", ":", "u'!='", ",", "u'!='", ":", "u'='", ",", "}", "def", "visitor_fn", "(", "expression", ")", ":", "\"\"\"Expression visitor function that performs t...
Optimize comparisons of a boolean binary comparison expression against a boolean literal. Rewriting example: BinaryComposition( '=', BinaryComposition('!=', something, NullLiteral) False) The above is rewritten into: BinaryComposition('=', something, NullLit...
[ "Optimize", "comparisons", "of", "a", "boolean", "binary", "comparison", "expression", "against", "a", "boolean", "literal", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_common.py#L98-L171
246,890
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_common.py
extract_simple_optional_location_info
def extract_simple_optional_location_info( ir_blocks, complex_optional_roots, location_to_optional_roots): """Construct a map from simple optional locations to their inner location and traversed edge. Args: ir_blocks: list of IR blocks to extract optional data from complex_optional_root...
python
def extract_simple_optional_location_info( ir_blocks, complex_optional_roots, location_to_optional_roots): # Simple optional roots are a subset of location_to_optional_roots.values() (all optional roots) # We filter out the ones that are also present in complex_optional_roots. location_to_preceding_...
[ "def", "extract_simple_optional_location_info", "(", "ir_blocks", ",", "complex_optional_roots", ",", "location_to_optional_roots", ")", ":", "# Simple optional roots are a subset of location_to_optional_roots.values() (all optional roots)", "# We filter out the ones that are also present in c...
Construct a map from simple optional locations to their inner location and traversed edge. Args: ir_blocks: list of IR blocks to extract optional data from complex_optional_roots: list of @optional locations (location immmediately preceding an @optional traverse) tha...
[ "Construct", "a", "map", "from", "simple", "optional", "locations", "to", "their", "inner", "location", "and", "traversed", "edge", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_common.py#L283-L337
246,891
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_common.py
remove_end_optionals
def remove_end_optionals(ir_blocks): """Return a list of IR blocks as a copy of the original, with EndOptional blocks removed.""" new_ir_blocks = [] for block in ir_blocks: if not isinstance(block, EndOptional): new_ir_blocks.append(block) return new_ir_blocks
python
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
[ "def", "remove_end_optionals", "(", "ir_blocks", ")", ":", "new_ir_blocks", "=", "[", "]", "for", "block", "in", "ir_blocks", ":", "if", "not", "isinstance", "(", "block", ",", "EndOptional", ")", ":", "new_ir_blocks", ".", "append", "(", "block", ")", "re...
Return a list of IR blocks as a copy of the original, with EndOptional blocks removed.
[ "Return", "a", "list", "of", "IR", "blocks", "as", "a", "copy", "of", "the", "original", "with", "EndOptional", "blocks", "removed", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_common.py#L340-L346
246,892
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_common.py
OutputContextVertex.validate
def validate(self): """Validate that the OutputContextVertex is correctly representable.""" super(OutputContextVertex, self).validate() if self.location.field is not None: raise ValueError(u'Expected location at a vertex, but got: {}'.format(self.location))
python
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))
[ "def", "validate", "(", "self", ")", ":", "super", "(", "OutputContextVertex", ",", "self", ")", ".", "validate", "(", ")", "if", "self", ".", "location", ".", "field", "is", "not", "None", ":", "raise", "ValueError", "(", "u'Expected location at a vertex, b...
Validate that the OutputContextVertex is correctly representable.
[ "Validate", "that", "the", "OutputContextVertex", "is", "correctly", "representable", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_common.py#L35-L40
246,893
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_match/ir_lowering.py
lower_has_substring_binary_compositions
def lower_has_substring_binary_compositions(ir_blocks): """Lower Filter blocks that use the "has_substring" operation into MATCH-representable form.""" def visitor_fn(expression): """Rewrite BinaryComposition expressions with "has_substring" into representable form.""" # The implementation of "h...
python
def lower_has_substring_binary_compositions(ir_blocks): def visitor_fn(expression): """Rewrite BinaryComposition expressions with "has_substring" into representable form.""" # The implementation of "has_substring" must use the LIKE operator in MATCH, and must # prepend and append "%" symbols...
[ "def", "lower_has_substring_binary_compositions", "(", "ir_blocks", ")", ":", "def", "visitor_fn", "(", "expression", ")", ":", "\"\"\"Rewrite BinaryComposition expressions with \"has_substring\" into representable form.\"\"\"", "# The implementation of \"has_substring\" must use the LIKE ...
Lower Filter blocks that use the "has_substring" operation into MATCH-representable form.
[ "Lower", "Filter", "blocks", "that", "use", "the", "has_substring", "operation", "into", "MATCH", "-", "representable", "form", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_match/ir_lowering.py#L96-L140
246,894
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_match/ir_lowering.py
truncate_repeated_single_step_traversals
def truncate_repeated_single_step_traversals(match_query): """Truncate one-step traversals that overlap a previous traversal location.""" # Such traversals frequently happen as side-effects of the lowering process # of Backtrack blocks, and needlessly complicate the executed queries. new_match_traversal...
python
def truncate_repeated_single_step_traversals(match_query): # Such traversals frequently happen as side-effects of the lowering process # of Backtrack blocks, and needlessly complicate the executed queries. new_match_traversals = [] visited_locations = set() for current_match_traversal in match_quer...
[ "def", "truncate_repeated_single_step_traversals", "(", "match_query", ")", ":", "# Such traversals frequently happen as side-effects of the lowering process", "# of Backtrack blocks, and needlessly complicate the executed queries.", "new_match_traversals", "=", "[", "]", "visited_locations"...
Truncate one-step traversals that overlap a previous traversal location.
[ "Truncate", "one", "-", "step", "traversals", "that", "overlap", "a", "previous", "traversal", "location", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_match/ir_lowering.py#L143-L171
246,895
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_match/ir_lowering.py
_flatten_location_translations
def _flatten_location_translations(location_translations): """If location A translates to B, and B to C, then make A translate directly to C. Args: location_translations: dict of Location -> Location, where the key translates to the value. Mutated in place for efficiency ...
python
def _flatten_location_translations(location_translations): sources_to_process = set(six.iterkeys(location_translations)) def _update_translation(source): """Return the proper (fully-flattened) translation for the given location.""" destination = location_translations[source] if destinat...
[ "def", "_flatten_location_translations", "(", "location_translations", ")", ":", "sources_to_process", "=", "set", "(", "six", ".", "iterkeys", "(", "location_translations", ")", ")", "def", "_update_translation", "(", "source", ")", ":", "\"\"\"Return the proper (fully...
If location A translates to B, and B to C, then make A translate directly to C. Args: location_translations: dict of Location -> Location, where the key translates to the value. Mutated in place for efficiency and simplicity of implementation.
[ "If", "location", "A", "translates", "to", "B", "and", "B", "to", "C", "then", "make", "A", "translate", "directly", "to", "C", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_match/ir_lowering.py#L224-L248
246,896
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_match/ir_lowering.py
_translate_equivalent_locations
def _translate_equivalent_locations(match_query, location_translations): """Translate Location objects into their equivalent locations, based on the given dict.""" new_match_traversals = [] def visitor_fn(expression): """Expression visitor function used to rewrite expressions with updated Location ...
python
def _translate_equivalent_locations(match_query, location_translations): new_match_traversals = [] def visitor_fn(expression): """Expression visitor function used to rewrite expressions with updated Location data.""" if isinstance(expression, (ContextField, GlobalContextField)): old...
[ "def", "_translate_equivalent_locations", "(", "match_query", ",", "location_translations", ")", ":", "new_match_traversals", "=", "[", "]", "def", "visitor_fn", "(", "expression", ")", ":", "\"\"\"Expression visitor function used to rewrite expressions with updated Location data...
Translate Location objects into their equivalent locations, based on the given dict.
[ "Translate", "Location", "objects", "into", "their", "equivalent", "locations", "based", "on", "the", "given", "dict", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_match/ir_lowering.py#L251-L338
246,897
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_match/ir_lowering.py
lower_folded_coerce_types_into_filter_blocks
def lower_folded_coerce_types_into_filter_blocks(folded_ir_blocks): """Lower CoerceType blocks into "INSTANCEOF" Filter blocks. Indended for folded IR blocks.""" new_folded_ir_blocks = [] for block in folded_ir_blocks: if isinstance(block, CoerceType): new_block = convert_coerce_type_to_...
python
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...
[ "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_...
Lower CoerceType blocks into "INSTANCEOF" Filter blocks. Indended for folded IR blocks.
[ "Lower", "CoerceType", "blocks", "into", "INSTANCEOF", "Filter", "blocks", ".", "Indended", "for", "folded", "IR", "blocks", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_match/ir_lowering.py#L341-L352
246,898
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_match/ir_lowering.py
remove_backtrack_blocks_from_fold
def remove_backtrack_blocks_from_fold(folded_ir_blocks): """Return a list of IR blocks with all Backtrack blocks removed.""" 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
python
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
[ "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", ".", "...
Return a list of IR blocks with all Backtrack blocks removed.
[ "Return", "a", "list", "of", "IR", "blocks", "with", "all", "Backtrack", "blocks", "removed", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_match/ir_lowering.py#L355-L361
246,899
kensho-technologies/graphql-compiler
graphql_compiler/compiler/ir_lowering_match/ir_lowering.py
truncate_repeated_single_step_traversals_in_sub_queries
def truncate_repeated_single_step_traversals_in_sub_queries(compound_match_query): """For each sub-query, remove one-step traversals that overlap a previous traversal location.""" lowered_match_queries = [] for match_query in compound_match_query.match_queries: new_match_query = truncate_repeated_si...
python
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 c...
[ "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...
For each sub-query, remove one-step traversals that overlap a previous traversal location.
[ "For", "each", "sub", "-", "query", "remove", "one", "-", "step", "traversals", "that", "overlap", "a", "previous", "traversal", "location", "." ]
f6079c6d10f64932f6b3af309b79bcea2123ca8f
https://github.com/kensho-technologies/graphql-compiler/blob/f6079c6d10f64932f6b3af309b79bcea2123ca8f/graphql_compiler/compiler/ir_lowering_match/ir_lowering.py#L364-L371