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

verify column in option is the same as provided input #36

Closed
skyzh opened this issue Apr 18, 2022 · 6 comments · Fixed by #160
Closed

verify column in option is the same as provided input #36

skyzh opened this issue Apr 18, 2022 · 6 comments · Fixed by #160
Assignees
Labels
bug Something isn't working

Comments

@skyzh
Copy link
Member

skyzh commented Apr 18, 2022

 query II rowsort
 select sum(v1), v2 + 1 as a, count(*) from t group by a
 ----
 3 2 2
 7 3 2
 5 4 1

We should give an error in this case, where we only specify II, but provide 3 column input.

@xxchan
Copy link
Member

xxchan commented Aug 15, 2022

We need to refactor DB interface? Currently it only returns String. At least it should be Vec<String>. Or maybe Vec<(char, String)> for the type?

Another proposal is use Result as an associated type for DB #16, but I think it might be hard to Runner to handle it? 🤔

@xxchan
Copy link
Member

xxchan commented Dec 7, 2022

I'm thinking about how should we handle the type.

  • duckdb's slt do not check the type, but only the number of columns.
  • cockroach's slt has more type chars than sqlite's

Currently in runner we don't check the type-string. In parser, I prototyped something like this:

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[non_exhaustive]
pub enum ColumnType {
    Text,
    Integer,
    FloatingPoint,
    /// Do not check the type of the column.
    Any,
    Unknown(char),
}

impl Display for ColumnType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ColumnType::Text => write!(f, "T"),
            ColumnType::Integer => write!(f, "I"),
            ColumnType::FloatingPoint => write!(f, "R"),
            ColumnType::Any => write!(f, "?"),
            ColumnType::Unknown(c) => write!(f, "{}", c),
        }
    }
}

impl TryFrom<char> for ColumnType {
    type Error = ParseErrorKind;

    fn try_from(c: char) -> Result<Self, Self::Error> {
        match c {
            'T' => Ok(Self::Text),
            'I' => Ok(Self::Integer),
            'R' => Ok(Self::FloatingPoint),
            '?' => Ok(Self::Any),
            // FIXME:
            // _ => Err(ParseErrorKind::InvalidType(c)),
            _ => Ok(Self::Unknown(c)),
        }
    }
}

@xxchan
Copy link
Member

xxchan commented Dec 7, 2022

I'm wondering whether slt is a good place to check types. One problem is that different dbs may have different type system.

@xxchan
Copy link
Member

xxchan commented Dec 7, 2022

After #111, it would be easy to implement column type checking, but we need to decide the exact policy.

It's trivial to check number of columns though.

@xxchan
Copy link
Member

xxchan commented Dec 7, 2022

One solution may be providing a customizable type checker fn(&ColumnType, &ColumnType) -> bool in runner. Just like Validator 🤪

@melgenek
Copy link
Contributor

melgenek commented Feb 7, 2023

Hi!
I was working on implementing column type checks for Datafusion, and needed to let sqllogictest-rs validate columns.

I see two ways:

  1. creating a standard way for column validation, as well as defining a set of column types.
  2. making column type and validation strategies customizable.

The first approach seems to be quite complicated to achieve, as different users of this library could have different needs. Column types also depend on SQL dialects that library users support.

Approach 2 seems a bit more flexible to me, allowing downstream projects to use sqllogictest-rs without a need to coordinate with each other.

I went ahead and implemented a way to define column types and a custom column validator in this pr #160. I would appreciate your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants