in mysqlx-connector-python/lib/mysqlx/expr.py [0:0]
def column_identifier(self) -> MessageType:
parts = []
parts.append(self.consume_token(TokenType.IDENT))
while self.cur_token_type_is(TokenType.DOT):
self.consume_token(TokenType.DOT)
parts.append(self.consume_token(TokenType.IDENT))
if len(parts) > 3:
raise ValueError(f"Too many parts to identifier at {self.pos}")
parts.reverse()
col_id = Message("Mysqlx.Expr.ColumnIdentifier")
# clever way to apply them to the struct
for i in range(0, len(parts)):
if i == 0:
col_id["name"] = parts[0]
elif i == 1:
col_id["table_name"] = parts[1]
elif i == 2:
col_id["schema_name"] = parts[2]
is_doc = False
if self.cur_token_type_is(TokenType.DOLLAR):
is_doc = True
self.consume_token(TokenType.DOLLAR)
col_id["document_path"] = self.document_path()
elif self.cur_token_type_is(TokenType.ARROW):
is_doc = True
self.consume_token(TokenType.ARROW)
is_quoted = False
if self.cur_token_type_is(TokenType.QUOTE):
is_quoted = True
self.consume_token(TokenType.QUOTE)
self.consume_token(TokenType.DOLLAR)
col_id["document_path"] = self.document_path()
if is_quoted:
self.consume_token(TokenType.QUOTE)
if is_doc and len(col_id["document_path"]) == 0:
doc_path_item = Message("Mysqlx.Expr.DocumentPathItem")
doc_path_item["type"] = mysqlxpb_enum(
"Mysqlx.Expr.DocumentPathItem.Type.MEMBER"
)
doc_path_item["value"] = ""
col_id["document_path"].extend([doc_path_item.get_message()])
msg_expr = Message("Mysqlx.Expr.Expr")
msg_expr["type"] = mysqlxpb_enum("Mysqlx.Expr.Expr.Type.IDENT")
msg_expr["identifier"] = col_id
return msg_expr