#include #include #include #include using namespace NSQLTranslation; using namespace NSQLTranslationV1; TSQLHints CollectHints(const TString& query, bool antlr4Parser) { bool ansi = false; auto lexer = MakeLexer(ansi, antlr4Parser); UNIT_ASSERT(lexer); TSQLHints result; NYql::TIssues issues; size_t maxErrors = 100; UNIT_ASSERT(CollectSqlHints(*lexer, query, "", "", result, issues, maxErrors, false)); UNIT_ASSERT(issues.Empty()); return result; } TString SerializeHints(const TVector& hints) { return JoinSeq(",", hints); } Y_UNIT_TEST_SUITE(TLexerHintsTests) { Y_UNIT_TEST(Basic) { TString query = "/*+ some() */ SELECT /*+ foo(one) */ --+ bar(two)"; auto hintsWithPos = CollectHints(query, false); UNIT_ASSERT(hintsWithPos.size() == 1); NYql::TPosition pos = hintsWithPos.begin()->first; TVector hints = hintsWithPos.begin()->second; UNIT_ASSERT_EQUAL(pos.Row, 1); UNIT_ASSERT_EQUAL(pos.Column, 15); TStringBuf expected = R"raw("foo":{"one"},"bar":{"two"})raw"; UNIT_ASSERT_NO_DIFF(SerializeHints(hints), expected); } Y_UNIT_TEST(Antlr4) { TString query = "/*+ some() */ SELECT /*+ foo(one) */ --+ bar(two)"; auto hintsWithPos = CollectHints(query, true); UNIT_ASSERT(hintsWithPos.size() == 1); NYql::TPosition pos = hintsWithPos.begin()->first; TVector hints = hintsWithPos.begin()->second; UNIT_ASSERT_EQUAL(pos.Row, 1); UNIT_ASSERT_EQUAL(pos.Column, 15); TStringBuf expected = R"raw("foo":{"one"},"bar":{"two"})raw"; UNIT_ASSERT_NO_DIFF(SerializeHints(hints), expected); } }