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

Better support for complex indexing statements #927

Open
maxice8 opened this issue Sep 19, 2024 · 1 comment
Open

Better support for complex indexing statements #927

maxice8 opened this issue Sep 19, 2024 · 1 comment
Assignees
Milestone

Comments

@maxice8
Copy link
Contributor

maxice8 commented Sep 19, 2024

Currently support for the indexing pattern is done by transforming each element of the list[str] by joining them with |

@property
def indexing_to_text(self) -> Optional[str]:
    if self.indexing is not None:
        return " | ".join(self.indexing)

This does not work well with certain indexing patterns, like switch, I have the following example:

indexing {
    input data_inicio | switch {
        case "None": input ano_inicio . "-01-01T00:00:00.00Z" | to_epoch_second | attribute | summary;
       default: input data_inicio . "T00:00:00.00Z" | to_epoch_second | attribute | summary;
   };
}

Translating it to PyVespa requires turning it into a single statement to use the switch:

# Instead of using the list[str] it splits it into a single 
indexing=[
    """input data_inicio | switch {
    case "None": input ano_inicio . "-01-01T00:00:00.00Z" | to_epoch_second | attribute | summary;
    default: input data_inicio . "T00:00:00.00Z" | to_epoch_second | attribute | summary;
}"""  # noqa: E501
],

Which results in (which works nicely):

indexing: input data_inicio | switch {
    case "None": input ano_inicio . "-01-01T00:00:00.00Z" | to_epoch_second | attribute | summary;
    default: input data_inicio . "T00:00:00.00Z" | to_epoch_second | attribute | summary;
}

Is this the intended way or is there a better way of writing indexing patterns that use switch or select_input?

@thomasht86 thomasht86 self-assigned this Sep 20, 2024
@oyving oyving added this to the soon milestone Sep 25, 2024
@thomasht86
Copy link
Collaborator

This is unfortunately how you need to do it today, but we definitely should make it a lot less ugly 😅
I will rename the issue accordingly.

@thomasht86 thomasht86 changed the title Clarification on handling multi-line indexing patterns Better support for complex indexing statements Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants