You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "jonathanc-n (via GitHub)" <gi...@apache.org> on 2024/10/15 20:13:40 UTC

[PR] Migrate Array Documentation [datafusion]

jonathanc-n opened a new pull request, #12948:
URL: https://github.com/apache/datafusion/pull/12948

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #12927 .
   
   ## Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   ## What changes are included in this PR?
   Moved the static array docs to the new one.
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ## Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
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-unsubscribe@datafusion.apache.org

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


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


Re: [PR] Migrate Array function Documentation to code [datafusion]

Posted by "Omega359 (via GitHub)" <gi...@apache.org>.
Omega359 commented on code in PR #12948:
URL: https://github.com/apache/datafusion/pull/12948#discussion_r1807872886


##########
docs/source/user-guide/sql/scalar_functions.md:
##########
@@ -2078,52 +669,6 @@ Transforms an array into rows.
 +-----------------------------------+
 ```
 
-### `range`
-
-Returns an Arrow array between start and stop with step. `SELECT range(2, 10, 3) -> [2, 5, 8]` or `SELECT range(DATE '1992-09-01', DATE '1993-03-01', INTERVAL '1' MONTH);`
-
-The range start..end contains all values with start <= x < end. It is empty if start >= end.
-
-Step can not be 0 (then the range will be nonsense.).
-
-Note that when the required range is a number, it accepts (stop), (start, stop), and (start, stop, step) as parameters, but when the required range is a date or timestamp, it must be 3 non-NULL parameters.
-For example,
-
-```
-SELECT range(3);
-SELECT range(1,5);
-SELECT range(1,5,1);
-```
-
-are allowed in number ranges
-
-but in date and timestamp ranges, only
-
-```
-SELECT range(DATE '1992-09-01', DATE '1993-03-01', INTERVAL '1' MONTH);
-SELECT range(TIMESTAMP '1992-09-01', TIMESTAMP '1993-03-01', INTERVAL '1' MONTH);
-```
-
-is allowed, and
-
-```
-SELECT range(DATE '1992-09-01', DATE '1993-03-01', NULL);
-SELECT range(NULL, DATE '1993-03-01', INTERVAL '1' MONTH);
-SELECT range(DATE '1992-09-01', NULL, INTERVAL '1' MONTH);
-```
-
-are not allowed
-
-#### Arguments
-
-- **start**: start of the range. Ints, timestamps, dates or string types that can be coerced to Date32 are supported.
-- **end**: end of the range (not included). Type must be the same as start.
-- **step**: increase by step (can not be 0). Steps less than a day are supported only for timestamp ranges.
-
-#### Aliases
-
-- generate_series
-
 ## Struct Functions
 
 - [unnest](#unnest-struct)

Review Comment:
   The only other special function I know of is make_map. See https://github.com/apache/datafusion/blob/972e3abea4286b0d06c44498d576c8498ddd3be2/datafusion/sql/src/expr/function.rs#L229



-- 
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-unsubscribe@datafusion.apache.org

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


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


Re: [PR] Migrate Array function Documentation to code [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #12948:
URL: https://github.com/apache/datafusion/pull/12948#discussion_r1802076218


##########
docs/source/user-guide/sql/scalar_functions.md:
##########
@@ -2078,52 +669,6 @@ Transforms an array into rows.
 +-----------------------------------+
 ```
 
-### `range`
-
-Returns an Arrow array between start and stop with step. `SELECT range(2, 10, 3) -> [2, 5, 8]` or `SELECT range(DATE '1992-09-01', DATE '1993-03-01', INTERVAL '1' MONTH);`
-
-The range start..end contains all values with start <= x < end. It is empty if start >= end.
-
-Step can not be 0 (then the range will be nonsense.).
-
-Note that when the required range is a number, it accepts (stop), (start, stop), and (start, stop, step) as parameters, but when the required range is a date or timestamp, it must be 3 non-NULL parameters.
-For example,
-
-```
-SELECT range(3);
-SELECT range(1,5);
-SELECT range(1,5,1);
-```
-
-are allowed in number ranges
-
-but in date and timestamp ranges, only
-
-```
-SELECT range(DATE '1992-09-01', DATE '1993-03-01', INTERVAL '1' MONTH);
-SELECT range(TIMESTAMP '1992-09-01', TIMESTAMP '1993-03-01', INTERVAL '1' MONTH);
-```
-
-is allowed, and
-
-```
-SELECT range(DATE '1992-09-01', DATE '1993-03-01', NULL);
-SELECT range(NULL, DATE '1993-03-01', INTERVAL '1' MONTH);
-SELECT range(DATE '1992-09-01', NULL, INTERVAL '1' MONTH);
-```
-
-are not allowed
-
-#### Arguments
-
-- **start**: start of the range. Ints, timestamps, dates or string types that can be coerced to Date32 are supported.
-- **end**: end of the range (not included). Type must be the same as start.
-- **step**: increase by step (can not be 0). Steps less than a day are supported only for timestamp ranges.
-
-#### Aliases
-
-- generate_series
-
 ## Struct Functions
 
 - [unnest](#unnest-struct)

Review Comment:
   I think `unnest` is special and not a scalar function. Perhaps as a follow on PR we can make a new page called "Special Functions" and put it there. 



##########
datafusion/functions-nested/src/extract.rs:
##########
@@ -314,6 +354,49 @@ impl ScalarUDFImpl for ArraySlice {
     fn aliases(&self) -> &[String] {
         &self.aliases
     }
+
+    fn documentation(&self) -> Option<&Documentation> {
+        Some(get_array_slice_doc())
+    }
+}
+
+fn get_array_slice_doc() -> &'static Documentation {
+    DOCUMENTATION.get_or_init(|| {
+        Documentation::builder()
+            .with_doc_section(DOC_SECTION_ARRAY)
+            .with_description(
+                "Returns a slice of the array based on 1-indexed start and end positions.",
+            )
+            .with_syntax_example("array_slice(array, begin, end)")

Review Comment:
   this example doesn't include `stride` but that is probably ok



##########
datafusion/functions-nested/src/make_array.rs:
##########
@@ -149,6 +153,39 @@ impl ScalarUDFImpl for MakeArray {
             )
         }
     }
+
+    fn documentation(&self) -> Option<&Documentation> {
+        Some(get_make_array_doc())
+    }
+}
+
+static DOCUMENTATION: OnceLock<Documentation> = OnceLock::new();
+
+fn get_make_array_doc() -> &'static Documentation {
+    DOCUMENTATION.get_or_init(|| {
+        Documentation::builder()
+            .with_doc_section(DOC_SECTION_ARRAY)
+            .with_description(
+                "Returns an Arrow array using the specified input expressions.",

Review Comment:
   I think `Arrow` is superflous, though I suspect it came from the original text and is not incorrect. It might be clearer to omit
   
   ```suggestion
                   "Returns an array using the specified input expressions.",
   ```



##########
datafusion/functions-nested/src/flatten.rs:
##########
@@ -95,6 +98,38 @@ impl ScalarUDFImpl for Flatten {
     fn aliases(&self) -> &[String] {
         &self.aliases
     }
+
+    fn documentation(&self) -> Option<&Documentation> {
+        Some(get_flatten_doc())
+    }
+}
+static DOCUMENTATION: OnceLock<Documentation> = OnceLock::new();
+
+fn get_flatten_doc() -> &'static Documentation {

Review Comment:
   this is so nice to have this documentation as part of the function



-- 
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-unsubscribe@datafusion.apache.org

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


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


Re: [PR] Migrate Array function Documentation to code [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #12948:
URL: https://github.com/apache/datafusion/pull/12948#issuecomment-2417022397

   I ran `./dev/update_function_docs.sh` and merged up from main to get the CI passing on 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: github-unsubscribe@datafusion.apache.org

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


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


Re: [PR] Migrate Array function Documentation to code [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #12948:
URL: https://github.com/apache/datafusion/pull/12948


-- 
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-unsubscribe@datafusion.apache.org

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


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


Re: [PR] Migrate Array function Documentation to code [datafusion]

Posted by "Omega359 (via GitHub)" <gi...@apache.org>.
Omega359 commented on code in PR #12948:
URL: https://github.com/apache/datafusion/pull/12948#discussion_r1808832107


##########
docs/source/user-guide/sql/scalar_functions.md:
##########
@@ -2078,52 +669,6 @@ Transforms an array into rows.
 +-----------------------------------+
 ```
 
-### `range`
-
-Returns an Arrow array between start and stop with step. `SELECT range(2, 10, 3) -> [2, 5, 8]` or `SELECT range(DATE '1992-09-01', DATE '1993-03-01', INTERVAL '1' MONTH);`
-
-The range start..end contains all values with start <= x < end. It is empty if start >= end.
-
-Step can not be 0 (then the range will be nonsense.).
-
-Note that when the required range is a number, it accepts (stop), (start, stop), and (start, stop, step) as parameters, but when the required range is a date or timestamp, it must be 3 non-NULL parameters.
-For example,
-
-```
-SELECT range(3);
-SELECT range(1,5);
-SELECT range(1,5,1);
-```
-
-are allowed in number ranges
-
-but in date and timestamp ranges, only
-
-```
-SELECT range(DATE '1992-09-01', DATE '1993-03-01', INTERVAL '1' MONTH);
-SELECT range(TIMESTAMP '1992-09-01', TIMESTAMP '1993-03-01', INTERVAL '1' MONTH);
-```
-
-is allowed, and
-
-```
-SELECT range(DATE '1992-09-01', DATE '1993-03-01', NULL);
-SELECT range(NULL, DATE '1993-03-01', INTERVAL '1' MONTH);
-SELECT range(DATE '1992-09-01', NULL, INTERVAL '1' MONTH);
-```
-
-are not allowed
-
-#### Arguments
-
-- **start**: start of the range. Ints, timestamps, dates or string types that can be coerced to Date32 are supported.
-- **end**: end of the range (not included). Type must be the same as start.
-- **step**: increase by step (can not be 0). Steps less than a day are supported only for timestamp ranges.
-
-#### Aliases
-
-- generate_series
-
 ## Struct Functions
 
 - [unnest](#unnest-struct)

Review Comment:
   Filed as https://github.com/apache/datafusion/issues/13036



-- 
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-unsubscribe@datafusion.apache.org

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


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


Re: [PR] Migrate Array Documentation [datafusion]

Posted by "jonathanc-n (via GitHub)" <gi...@apache.org>.
jonathanc-n commented on PR #12948:
URL: https://github.com/apache/datafusion/pull/12948#issuecomment-2414923770

   @Omega359 @alamb Not to sure where to put the unnest documentation 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: github-unsubscribe@datafusion.apache.org

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


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


Re: [PR] Migrate Array function Documentation to code [datafusion]

Posted by "jonathanc-n (via GitHub)" <gi...@apache.org>.
jonathanc-n commented on code in PR #12948:
URL: https://github.com/apache/datafusion/pull/12948#discussion_r1802086300


##########
docs/source/user-guide/sql/scalar_functions.md:
##########
@@ -2078,52 +669,6 @@ Transforms an array into rows.
 +-----------------------------------+
 ```
 
-### `range`
-
-Returns an Arrow array between start and stop with step. `SELECT range(2, 10, 3) -> [2, 5, 8]` or `SELECT range(DATE '1992-09-01', DATE '1993-03-01', INTERVAL '1' MONTH);`
-
-The range start..end contains all values with start <= x < end. It is empty if start >= end.
-
-Step can not be 0 (then the range will be nonsense.).
-
-Note that when the required range is a number, it accepts (stop), (start, stop), and (start, stop, step) as parameters, but when the required range is a date or timestamp, it must be 3 non-NULL parameters.
-For example,
-
-```
-SELECT range(3);
-SELECT range(1,5);
-SELECT range(1,5,1);
-```
-
-are allowed in number ranges
-
-but in date and timestamp ranges, only
-
-```
-SELECT range(DATE '1992-09-01', DATE '1993-03-01', INTERVAL '1' MONTH);
-SELECT range(TIMESTAMP '1992-09-01', TIMESTAMP '1993-03-01', INTERVAL '1' MONTH);
-```
-
-is allowed, and
-
-```
-SELECT range(DATE '1992-09-01', DATE '1993-03-01', NULL);
-SELECT range(NULL, DATE '1993-03-01', INTERVAL '1' MONTH);
-SELECT range(DATE '1992-09-01', NULL, INTERVAL '1' MONTH);
-```
-
-are not allowed
-
-#### Arguments
-
-- **start**: start of the range. Ints, timestamps, dates or string types that can be coerced to Date32 are supported.
-- **end**: end of the range (not included). Type must be the same as start.
-- **step**: increase by step (can not be 0). Steps less than a day are supported only for timestamp ranges.
-
-#### Aliases
-
-- generate_series
-
 ## Struct Functions
 
 - [unnest](#unnest-struct)

Review Comment:
   Yeah, I can create one for that



-- 
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-unsubscribe@datafusion.apache.org

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


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


Re: [PR] Migrate Array function Documentation to code [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #12948:
URL: https://github.com/apache/datafusion/pull/12948#issuecomment-2417439196

   🚀 


-- 
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-unsubscribe@datafusion.apache.org

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


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