コード例 #1
0
    def _(self, schema: ParamSchema.Multicolumn, value: List[str]) -> str:
        valid_columns = self.output_columns_for_tab_parameter(
            schema.tab_parameter)

        error_agg = PromptingErrorAggregator()
        requested_colnames = set(value)

        valid_colnames = []
        # ignore colnames not in valid_columns
        # iterate in table order
        for colname, column in valid_columns.items():
            if colname not in requested_colnames:
                continue

            if (schema.column_types and _column_type_name(column.type)
                    not in schema.column_types):
                if "text" in schema.column_types:
                    found_type = None
                else:
                    found_type = _column_type_name(column.type)
                error_agg.add(
                    PromptingError.WrongColumnType([column.name], found_type,
                                                   schema.column_types))
            else:
                valid_colnames.append(column.name)

        error_agg.raise_if_nonempty()

        return valid_colnames
コード例 #2
0
def _(
    schema: ParamSchema.Multicolumn, value: List[str], input_metadata: TableMetadata
) -> str:
    if schema.tab_parameter:
        raise RuntimeError("Unsupported: fetch multicolumn with tab_parameter")

    error_agg = PromptingErrorAggregator()
    requested_colnames = set(value)

    valid_colnames = []
    # ignore colnames not in valid_columns
    # iterate in table order
    for column in input_metadata.columns:
        if column.name not in requested_colnames:
            continue

        if (
            schema.column_types
            and _column_type_name(column.type) not in schema.column_types
        ):
            if "text" in schema.column_types:
                found_type = None
            else:
                found_type = _column_type_name(column.type)
            error_agg.add(
                PromptingError.WrongColumnType(
                    [column.name], found_type, schema.column_types
                )
            )
        else:
            valid_colnames.append(column.name)

    error_agg.raise_if_nonempty()

    return valid_colnames
コード例 #3
0
 def clean_value_list(self, schema: ParamSchema.List,
                      value: List[Any]) -> List[Any]:
     ret = []
     error_agg = PromptingErrorAggregator()
     for v in value:
         try:
             ret.append(self.clean_value(schema.inner_schema, v))
         except PromptingError as err:
             error_agg.extend(err.errors)
     error_agg.raise_if_nonempty()
     return ret
コード例 #4
0
    def _(self, schema: ParamSchema.Dict, value: Dict[str,
                                                      Any]) -> Dict[str, Any]:
        ret = {}
        error_agg = PromptingErrorAggregator()

        for k, v in value.items():
            try:
                ret[k] = self.clean_value(schema.properties[k], v)
            except PromptingError as err:
                error_agg.extend(err.errors)

        error_agg.raise_if_nonempty()
        return ret
コード例 #5
0
def clean_value_list(
    schema: ParamSchema.List, value: List[Any], input_metadata: TableMetadata
) -> List[Any]:
    inner_clean = partial(clean_value, schema.inner_schema)
    ret = []
    error_agg = PromptingErrorAggregator()
    for v in value:
        try:
            ret.append(inner_clean(v, input_metadata))
        except PromptingError as err:
            error_agg.extend(err.errors)
    error_agg.raise_if_nonempty()
    return ret
コード例 #6
0
 def _(self, schema: ParamSchema.Condition,
       value: Dict[str, Any]) -> Optional[Dict[str, Any]]:
     condition, errors = _clean_condition_recursively(
         value,
         {
             column.name: _column_type_name(column.type)
             for column in self.input_table_columns
         },
     )
     error_agg = PromptingErrorAggregator()
     for error in errors:
         error_agg.add(error)
     error_agg.raise_if_nonempty()
     return condition
コード例 #7
0
    def _(self, schema: ParamSchema.Multichartseries,
          value: List[Dict[str, str]]) -> List[Dict[str, str]]:
        # Recurse to clean_value(ParamSchema.Column) to clear missing columns
        inner_schema = ParamSchema.Dict({
            "color":
            ParamSchema.String(default="#000000"),
            "column":
            ParamSchema.Column(column_types=frozenset(["number"])),
        })

        ret = []
        error_agg = PromptingErrorAggregator()

        for v in value:
            try:
                clean_v = self.clean_value(inner_schema, v)
                if clean_v["column"]:  # it's a valid column
                    ret.append(clean_v)
            except PromptingError as err:
                error_agg.extend(err.errors)

        error_agg.raise_if_nonempty()
        return ret