Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow casting of type variables to value variables #329

Open
shreyas1599 opened this issue Apr 10, 2024 · 3 comments
Open

Allow casting of type variables to value variables #329

shreyas1599 opened this issue Apr 10, 2024 · 3 comments

Comments

@shreyas1599
Copy link

Problem to Solve

Currently, instance variables can be casted into value variables and the below query is valid.

match $entity isa entity-name has attribute-one $attributeOne;
?attributeValue = $attributeOne;
fetch nestedQuery: {
    match $anotherEntity is another-entity-name, has attribute-two ?attributeValue;
    fetch $anotherEntity: attribute;
};

But the same cannot be done with a type variable. For example, the below query is invalid. The below use case is to fetch the super types of an entity and then use a subquery to fetch another entity with an attribute filter that depends on the label of the supertype. Essentially, it's trying to cast a type variable into a value variable.

Query 1

match $someEntity isa $someEntityType, has id "some id";
$someEntityType sub entity;
not { $someEntityType sub someEntityType; };
?someEntityTypeValue = $someEntityType; # illegal operation
fetch $someEntityType;
metadataOfSomeEntity: {
    match $metadata isa metadata, has entity-type ?someEntityTypeValue;
    fetch $metadata: attribute;
};

Current Workaround

To run the aforementioned query, first get the labels of $someEntityType and then pass them into another query to run the sub query from above (metadataOfSomeEntity) either as a single query by using the OR operator or running them as separate queries for each of the labels.

Proposed Solution

To be able to run Query 1 without splitting it into >1 queries - support the casting of type variables to value variables.

@dmitrii-ubskii dmitrii-ubskii changed the title Allow casting of type variables to value variables Allow casting of thing variables to value variables Jun 26, 2024
@dmitrii-ubskii dmitrii-ubskii changed the title Allow casting of thing variables to value variables Allow casting of type variables to value variables Jun 26, 2024
@dmitrii-ubskii
Copy link
Member

I'm confused. What should the value variable contain after such a cast? The type label as a string?

@shreyas1599
Copy link
Author

yes

@dmitrii-ubskii
Copy link
Member

That's an intriguing proposal. We'll come back to it once we have some spare bandwidth!

@dmitrii-ubskii dmitrii-ubskii self-assigned this Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants