コード例 #1
0
def test_parse_value_without_closing_double_semicolons():
    stream = (
        tokens.ExpressionBlockToken("SELECT * FROM TABLE", 1),
        tokens.StreamEndToken(1),
    )
    parser = lkml.parser.Parser(stream)
    result = parser.parse_value()
    assert result is None
コード例 #2
0
ファイル: lexer.py プロジェクト: jamescurtin/lkml
 def scan_expression_block(self) -> tokens.ExpressionBlockToken:
     chars = ""
     while self.peek_multiple(2) != ";;":
         if self.peek() == "\n":
             self.line_number += 1
         chars += self.consume()
     # Strip any trailing whitespace from the expression
     # Usually there is an extra space before the ;;
     chars = chars.rstrip()
     return tokens.ExpressionBlockToken(chars, self.line_number)
コード例 #3
0
def test_scan_with_complex_sql_block():
    text = ("sql_distinct_key: concat(${orders.order_id}, '|', "
            "${orders__items.primary_key}) ;;")
    output = lkml.Lexer(text).scan()
    assert output == (
        tokens.StreamStartToken(1),
        tokens.LiteralToken("sql_distinct_key", 1),
        tokens.ValueToken(1),
        tokens.ExpressionBlockToken(
            " concat(${orders.order_id}, '|', ${orders__items.primary_key}) ",
            1),
        tokens.ExpressionBlockEndToken(1),
        tokens.StreamEndToken(1),
    )
コード例 #4
0
ファイル: test_parser.py プロジェクト: LewisCharlesBaker/lkml
def test_parse_pair_with_sql_block():
    sql = " SELECT * FROM schema.table "
    stream = (
        tokens.LiteralToken("sql", 1),
        tokens.ValueToken(1),
        tokens.WhitespaceToken(" ", 1),
        tokens.ExpressionBlockToken(sql, 1),
        tokens.ExpressionBlockEndToken(1),
        tokens.StreamEndToken(1),
    )
    parser = lkml.parser.Parser(stream)
    result = parser.parse_pair()
    assert result == PairNode(
        type=SyntaxToken("sql"), value=ExpressionSyntaxToken(sql.strip())
    )
コード例 #5
0
ファイル: lexer.py プロジェクト: yswang0927/lkml
    def scan_expression_block(self) -> tokens.ExpressionBlockToken:
        """Returns an token from an expression block string.

        This method strips any trailing whitespace from the expression string, since
        Looker usually adds an extra space before the `;;` terminal.

        Example:
            >>> lexer = Lexer("SELECT * FROM ${TABLE} ;;")
            >>> lexer.scan_expression_block()
            ExpressionBlockToken(SELECT * FROM ${TABLE})

        """
        chars = ""
        while self.peek_multiple(2) != ";;":
            if self.peek() == "\n":
                self.line_number += 1
            chars += self.consume()
        return tokens.ExpressionBlockToken(chars, self.line_number)
コード例 #6
0
def parser():
    stream = (
        tokens.StreamStartToken(1),
        tokens.LiteralToken("view", 1),
        tokens.ValueToken(1),
        tokens.LiteralToken("view_name", 1),
        tokens.BlockStartToken(1),
        tokens.LiteralToken("sql_table_name", 2),
        tokens.ValueToken(2),
        tokens.ExpressionBlockToken("schema.table_name", 2),
        tokens.ExpressionBlockEndToken(2),
        tokens.LiteralToken("drill_fields", 3),
        tokens.ValueToken(3),
        tokens.ListStartToken(3),
        tokens.LiteralToken("view_name.field_one", 3),
        tokens.CommaToken(3),
        tokens.LiteralToken("view_name.field_two", 3),
        tokens.ListEndToken(3),
        tokens.BlockEndToken(4),
        tokens.StreamEndToken(4),
    )
    return lkml.parser.Parser(stream)
コード例 #7
0
def test_tokens__repr__():
    token = tokens.ExpressionBlockToken("schema.table_name", 2)
    repr(token) == "ExpressionBlockToken(schema.table_name)"
コード例 #8
0
ファイル: test_lexer.py プロジェクト: stjordanis/lkml
def test_scan_expression_block_with_complex_sql_block():
    text = "concat(${orders.order_id}, '|',\n${orders__items.primary_key}) ;;"
    token = lkml.Lexer(text).scan_expression_block()
    token == tokens.ExpressionBlockToken(
        "concat(${orders.order_id}, '|', ${orders__items.primary_key})", 1
    )