pyvespa icon indicating copy to clipboard operation
pyvespa copied to clipboard

Clarification on handling multi-line indexing patterns

Open maxice8 opened this issue 5 months ago • 0 comments

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?

maxice8 avatar Sep 19 '24 09:09 maxice8