hansott commented on code in PR #1677:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1677#discussion_r1930597945


##########
src/tokenizer.rs:
##########
@@ -2227,6 +2260,43 @@ mod tests {
         compare(expected, tokens);
     }
 
+    #[test]
+    fn tokenize_numeric_literal_underscore() {
+        let dialect = GenericDialect {};
+        let sql = String::from("SELECT 10_000");
+        let mut tokenizer = Tokenizer::new(&dialect, &sql);
+        let tokens = tokenizer.tokenize().unwrap();
+        let expected = vec![
+            Token::make_keyword("SELECT"),
+            Token::Whitespace(Whitespace::Space),
+            Token::Number("10".to_string(), false),
+            Token::make_word("_000", None),
+        ];
+        compare(expected, tokens);
+
+        let dialect = ClickHouseDialect {};
+        let sql = String::from("SELECT 10_000, _10_000, 10_00_, 10___0");
+        let mut tokenizer = Tokenizer::new(&dialect, &sql);
+        let tokens = tokenizer.tokenize().unwrap();
+        let expected = vec![
+            Token::make_keyword("SELECT"),
+            Token::Whitespace(Whitespace::Space),
+            Token::Number("10_000".to_string(), false),
+            Token::Comma,
+            Token::Whitespace(Whitespace::Space),
+            Token::make_word("_10_000", None), // leading underscore tokenizes 
as a word (parsed as column identifier)
+            Token::Comma,
+            Token::Whitespace(Whitespace::Space),
+            Token::Number("10_00".to_string(), false),
+            Token::make_word("_", None), // trailing underscores tokenizes as 
a word (syntax error in some dialects)
+            Token::Comma,
+            Token::Whitespace(Whitespace::Space),
+            Token::Number("10".to_string(), false),
+            Token::make_word("___0", None), // multiple underscores tokenizes 
as a word (syntax error in some dialects)
+        ];
+        compare(expected, tokens);

Review Comment:
   There's a utility `.tokenizes_to(...)` that might be useful for tests like 
this :) 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to