slackhq / hack-sql-fake

A library for testing database driven code in Hack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: Parser does not know about some Operators

lexidor opened this issue · comments

Issue template for hack-sql-fake

  • [ X ] Question

Question

QQ: I took a Keyset\diff of Operator::getValues() and SQLParser::OPERATORS. There are some operators that the parser does not know about that do have an implementation in the rest of the code. Think of RLIKE. Others are only used in this block.

      case Operator::ANY: // parser does NOT KNOW about this functionality
      case Operator::SOME: // parser does NOT KNOW about this functionality
      //[[fallthrough]] <- note to humans, not to the typechecker, therefore different syntax.
      default:
        throw new SQLFakeRuntimeException("Operator {$this->operator} not implemented in SQLFake");

For maintainability I would like to end up with declaring the enum only once. This will require some filtering on the SQLParser constant. This will nolonger allow it to be a constant. Could something like this be done in the future?

class SQLParser{
  visibility static function getParsableOperators(): keyset<Operator>{
    return Keyset\filter(Operator::getValues(), $op ==> self::isImplemented($op));
  }
}

Another solution is that we just implement ANY and SOME in the parser. I can't remember now why it's not implemented, but it seems like it'd be nice to just have one enum. I'd like to keep it as an enum, I think enums are the best solution due to switch exhaustiveness checking and switch statement performance.

I think the parser extension will have to be done by @someone_else. I don't have enough confidence in my knowledge of the codebase just yet.