Re: [PR] [5201]Implement expressions in python client [gravitino]
SophieTech88 commented on code in PR #5646: URL: https://github.com/apache/gravitino/pull/5646#discussion_r1857676618 ## clients/client-python/gravitino/api/expressions/Literals/literal.py: ## @@ -0,0 +1,39 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from abc import abstractmethod +from typing import List + +from gravitino.api.expressions.expression import Expression + + +class Literal(Expression): +""" +Represents a constant literal value in the public expression API. +""" + +@abstractmethod +def value(self): +"""The literal value.""" +pass + +@abstractmethod +def data_type(self): Review Comment: Agree. Just updated the code to raise NotImplementedError() for those 2 functions. -- 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: commits-unsubscr...@gravitino.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [5201]Implement expressions in python client [gravitino]
tengqm commented on code in PR #5646: URL: https://github.com/apache/gravitino/pull/5646#discussion_r1856494813 ## clients/client-python/gravitino/api/expressions/Literals/literal.py: ## @@ -0,0 +1,39 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from abc import abstractmethod +from typing import List + +from gravitino.api.expressions.expression import Expression + + +class Literal(Expression): +""" +Represents a constant literal value in the public expression API. +""" + +@abstractmethod +def value(self): +"""The literal value.""" +pass + +@abstractmethod +def data_type(self): Review Comment: Sounds like that the above two methods are be implemented by subclasses anyway. If that is true, I don't think we we do a `pass` here. We may want to raise an exception instead. ## clients/client-python/gravitino/api/expressions/Literals/literals.py: ## @@ -0,0 +1,138 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from decimal import Decimal +from typing import Union +from datetime import date, time, datetime + +from gravitino.api.expressions.literals.literal import Literal + + +class LiteralImpl(Literal): +"""Creates a literal with the given type value.""" + +_value: Union[int, float, str, datetime, time, date, bool, Decimal, None] +_data_type: ( +str # TODO: Need implement `api/src/main/java/org/apache/gravitino/rel/types` +) + +def __init__( +self, +value: Union[int, float, str, datetime, time, date, bool, Decimal, None], Review Comment: Why do we have a `Decimal` here? -- 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: commits-unsubscr...@gravitino.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [5201]Implement expressions in python client [gravitino]
xunliu commented on PR #5646: URL: https://github.com/apache/gravitino/pull/5646#issuecomment-2497715895 hi @SophieTech88 I will help you improve this PR. Please review my commit. -- 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: commits-unsubscr...@gravitino.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [5201]Implement expressions in python client [gravitino]
SophieTech88 commented on code in PR #5646: URL: https://github.com/apache/gravitino/pull/5646#discussion_r1855831796 ## clients/client-python/gravitino/api/expressions/named_reference.py: ## @@ -0,0 +1,76 @@ +# Licensed to the Apache Software Foundation (ASF) under one Review Comment: @xunliu Do you have any idea about the name for this feature? -- 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: commits-unsubscr...@gravitino.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [5201]Implement expressions in python client [gravitino]
jerryshao commented on PR #5646: URL: https://github.com/apache/gravitino/pull/5646#issuecomment-2496601874 @mchades @xunliu would you please also help to review this PR? -- 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: commits-unsubscr...@gravitino.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [5201]Implement expressions in python client [gravitino]
SophieTech88 commented on code in PR #5646: URL: https://github.com/apache/gravitino/pull/5646#discussion_r1855126932 ## clients/client-python/gravitino/api/expressions/named_reference.py: ## @@ -0,0 +1,76 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations +from typing import List +from gravitino.api.expressions.expression import Expression + + +class NamedReference(Expression): +""" +Represents a field or column reference in the public logical expression API. +""" + +@staticmethod +def field(field_name: List[str]) -> FieldReference: +"""Returns a FieldReference for the given field name(s).""" +return FieldReference(field_name) + +@staticmethod +def field_from_column(column_name: str) -> FieldReference: +"""Returns a FieldReference for the given column name.""" +return FieldReference([column_name]) + +def field_name(self) -> List[str]: +""" +Returns the referenced field name as a list of string parts. +Must be implemented by subclasses. +""" +raise NotImplementedError("Subclasses must implement this method.") + +def children(self) -> List[Expression]: +"""Named references do not have children.""" +return Expression.EMPTY_EXPRESSION + +def references(self) -> List[NamedReference]: +"""Named references reference themselves.""" +return [self] + + +class FieldReference(NamedReference): +""" +A NamedReference that references a field or column. +""" + +def __init__(self, field_name: List[str]): +super().__init__() +self._field_name = field_name Review Comment: Yeah. Just updated it. -- 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: commits-unsubscr...@gravitino.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [5201]Implement expressions in python client [gravitino]
SophieTech88 commented on code in PR #5646: URL: https://github.com/apache/gravitino/pull/5646#discussion_r1855126556 ## clients/client-python/gravitino/api/expressions/named_reference.py: ## @@ -0,0 +1,76 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations +from typing import List +from gravitino.api.expressions.expression import Expression + + +class NamedReference(Expression): +""" +Represents a field or column reference in the public logical expression API. +""" + +@staticmethod +def field(field_name: List[str]) -> FieldReference: +"""Returns a FieldReference for the given field name(s).""" +return FieldReference(field_name) + +@staticmethod +def field_from_column(column_name: str) -> FieldReference: +"""Returns a FieldReference for the given column name.""" +return FieldReference([column_name]) + +def field_name(self) -> List[str]: +""" +Returns the referenced field name as a list of string parts. +Must be implemented by subclasses. +""" +raise NotImplementedError("Subclasses must implement this method.") + +def children(self) -> List[Expression]: +"""Named references do not have children.""" +return Expression.EMPTY_EXPRESSION + +def references(self) -> List[NamedReference]: +"""Named references reference themselves.""" +return [self] + + +class FieldReference(NamedReference): +""" +A NamedReference that references a field or column. +""" + +def __init__(self, field_name: List[str]): +super().__init__() +self._field_name = field_name + +def field_name(self) -> List[str]: Review Comment: It is a good suggestion. Just updated the `field_name` to `field_names`. -- 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: commits-unsubscr...@gravitino.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [5201]Implement expressions in python client [gravitino]
SophieTech88 commented on code in PR #5646: URL: https://github.com/apache/gravitino/pull/5646#discussion_r1855125964 ## clients/client-python/gravitino/api/expressions/function_expression.py: ## @@ -0,0 +1,90 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + + +from __future__ import annotations +from abc import abstractmethod +from typing import List, Union +from gravitino.api.expressions.expression import Expression + + +class FunctionExpression(Expression): +""" +The interface of a function expression. A function expression is an expression that takes a +function name and a list of arguments. +""" + +@staticmethod +def of(function_name: str, *arguments: Expression) -> FuncExpressionImpl: +""" +Creates a new FunctionExpression with the given function name. +If no arguments are provided, it uses an empty expression. + +:param function_name: The name of the function. +:param arguments: The arguments to the function (optional). +:return: The created FunctionExpression. +""" +arguments = list(arguments) if arguments else Expression.EMPTY_EXPRESSION +return FuncExpressionImpl(function_name, arguments) + +@abstractmethod +def function_name(self) -> str: +"""Returns the function name.""" +pass + +@abstractmethod +def arguments(self) -> List[Expression]: +"""Returns the arguments passed to the function.""" +pass + +def children(self) -> List[Expression]: +"""Returns the arguments as children.""" +return self.arguments() + + +class FuncExpressionImpl(FunctionExpression): +""" +A concrete implementation of the FunctionExpression interface. +""" + +def __init__(self, function_name: str, arguments: List[Expression]): +super().__init__() +self._function_name = function_name +self._arguments = arguments + +def function_name(self) -> str: +return self._function_name + +def arguments(self) -> List[Expression]: +return self._arguments + +def __str__(self) -> str: +if not self._arguments: +return f"{self._function_name}()" +arguments_str = ", ".join(map(str, self._arguments)) +return f"{self._function_name}({arguments_str})" + +def __eq__(self, other: Union[FuncExpressionImpl, object]) -> bool: +if isinstance(other, FuncExpressionImpl): +return ( +self._function_name == other._function_name +and self._arguments == other._arguments +) +return False Review Comment: Thanks for your comment. Updated the TODO comment. Does that work for you? -- 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: commits-unsubscr...@gravitino.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] [5201]Implement expressions in python client [gravitino]
tengqm commented on code in PR #5646: URL: https://github.com/apache/gravitino/pull/5646#discussion_r1853747579 ## clients/client-python/gravitino/api/expressions/named_reference.py: ## @@ -0,0 +1,76 @@ +# Licensed to the Apache Software Foundation (ASF) under one Review Comment: Why do we call this a named reference? Is there a case where a reference has no name? Do we have to differentiate these two types of references? ## clients/client-python/gravitino/api/expressions/named_reference.py: ## @@ -0,0 +1,76 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations +from typing import List +from gravitino.api.expressions.expression import Expression + + +class NamedReference(Expression): +""" +Represents a field or column reference in the public logical expression API. +""" + +@staticmethod +def field(field_name: List[str]) -> FieldReference: +"""Returns a FieldReference for the given field name(s).""" +return FieldReference(field_name) + +@staticmethod +def field_from_column(column_name: str) -> FieldReference: +"""Returns a FieldReference for the given column name.""" +return FieldReference([column_name]) + +def field_name(self) -> List[str]: +""" +Returns the referenced field name as a list of string parts. +Must be implemented by subclasses. +""" +raise NotImplementedError("Subclasses must implement this method.") + +def children(self) -> List[Expression]: +"""Named references do not have children.""" +return Expression.EMPTY_EXPRESSION + +def references(self) -> List[NamedReference]: +"""Named references reference themselves.""" +return [self] + + +class FieldReference(NamedReference): +""" +A NamedReference that references a field or column. +""" + +def __init__(self, field_name: List[str]): +super().__init__() +self._field_name = field_name Review Comment: rename `_field_name` to `_field_names` ? Looks like this field is an array. ## clients/client-python/gravitino/api/expressions/named_reference.py: ## @@ -0,0 +1,76 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations +from typing import List +from gravitino.api.expressions.expression import Expression + + +class NamedReference(Expression): +""" +Represents a field or column reference in the public logical expression API. +""" + +@staticmethod +def field(field_name: List[str]) -> FieldReference: +"""Returns a FieldReference for the given field name(s).""" +return FieldReference(field_name) + +@staticmethod +def field_from_column(column_name: str) -> FieldReference: +"""Returns a FieldReference for the given column name.""" +return FieldReference([column_name]) + +def field_name(self) -> List[str]: +""" +Returns the referenced field name as a list of string parts. +Must be implemented by subclasses. +""" +raise NotImplementedError("Subclasses must implement this method.") + +def children(self) -> List[Expression]: +"""Named references do not have children.""" +return Expression.EMPTY_EXPRESSION + +def references(self) -> List[NamedReference]: +"""Named references reference themselves.""" +return [self] + + +class Fiel