-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up basic CI, added tests, and implemented the mode function. (#2)
* Set up basic CI, added tests, and implemented the mode function.
- Loading branch information
Showing
24 changed files
with
3,832 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
||
[*.rs] | ||
indent_style = space | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# 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. | ||
|
||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- '**' | ||
pull_request: {} | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install Rust toolchain components | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
components: rustfmt, clippy | ||
|
||
- id: cache-rust | ||
uses: Swatinem/rust-cache@v2 | ||
|
||
- name: Run pre-commit lint checks | ||
uses: pre-commit/[email protected] | ||
with: | ||
extra_args: --all-files --verbose | ||
env: | ||
PRE_COMMIT_COLOR: always | ||
SKIP: test | ||
|
||
test: | ||
name: Test with Rust-${{ matrix.rust-version }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
rust-version: [stable, nightly] | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Rust toolchain | ||
uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: ${{ matrix.rust-version }} | ||
|
||
- id: cache-rust | ||
uses: Swatinem/rust-cache@v2 | ||
|
||
- name: Run cargo tests | ||
run: cargo test --all-features |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,59 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
debug/ | ||
target/ | ||
# License | ||
# 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. | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
# Linux perf sample data | ||
perf.data | ||
perf.data.old | ||
|
||
# IDE and editor directories | ||
.vscode | ||
.idea/ | ||
.pytest_cache/ | ||
|
||
# Python virtual environments | ||
venv/* | ||
|
||
# macOS | ||
.DS_Store | ||
|
||
# Docker volumes used for caching | ||
.docker | ||
|
||
# Rust build output | ||
target | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
# Backup files | ||
*.orig | ||
.gdb_history | ||
.history | ||
|
||
# Swap files | ||
.*.swp | ||
.*.swo | ||
|
||
# Rust-specific tools | ||
rusty-tags.vi | ||
|
||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb | ||
# Apache release artifacts | ||
dev/dist | ||
|
||
# RustRover | ||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can | ||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
# and can be added to the global gitignore or merged into this file. For a more nuclear | ||
# option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
#.idea/ | ||
# Apache RAT report files | ||
filtered_rat.txt | ||
rat.txt | ||
.githubchangeloggenerator.cache* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# 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. | ||
|
||
fail_fast: true | ||
|
||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.0.1 | ||
hooks: | ||
- id: check-yaml | ||
- id: check-toml | ||
- id: end-of-file-fixer | ||
- id: trailing-whitespace | ||
- id: check-added-large-files | ||
|
||
- repo: local | ||
hooks: | ||
- id: format | ||
name: Format | ||
entry: cargo fmt | ||
types: [rust] | ||
language: system | ||
pass_filenames: false | ||
- id: clippy | ||
name: Clippy | ||
entry: cargo clippy -- -D warnings | ||
types: [rust] | ||
language: system | ||
pass_filenames: false | ||
- id: test | ||
name: Test | ||
entry: cargo test | ||
types: [rust] | ||
language: system | ||
pass_filenames: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# 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. | ||
|
||
max_width = 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# 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. | ||
|
||
[package] | ||
name = "datafusion-functions-extra" | ||
version = "0.1.0" | ||
edition = "2021" | ||
description = "Extra Functions for DataFusion" | ||
readme = "README.md" | ||
license = "Apache-2.0" | ||
keywords = ["datafusion", "functions-extra", "aggregations"] | ||
repository = "https://github.com/datafusion-contrib/datafusion-functions-extra/" | ||
rust-version = "1.76" | ||
|
||
[lib] | ||
name = "datafusion_functions_extra" | ||
path = "src/lib.rs" | ||
|
||
[dependencies] | ||
ahash = { version = "0.8", default-features = false, features = [ | ||
"runtime-rng", | ||
] } | ||
datafusion = "42" | ||
hashbrown = { version = "0.14.5", features = ["raw"] } | ||
log = "^0.4" | ||
paste = "1" | ||
|
||
[dev-dependencies] | ||
arrow = { version = "53.0.0", features = ["test_utils"] } | ||
criterion = { version = "0.5", features = ["async_tokio"] } | ||
insta = { version = "1.40.0", features = ["yaml"] } | ||
tokio = { version = "1.36", features = ["full"] } | ||
|
||
[lints.clippy] | ||
dbg_macro = "deny" | ||
print_stdout = "deny" | ||
|
||
[[bench]] | ||
name = "mode" | ||
harness = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# datafusion-functions-extra | ||
|
||
[![CI](https://github.com/datafusion-contrib/datafusion-functions-extra/actions/workflows/ci.yml/badge.svg?event=push)](https://github.com/datafusion-contrib/datafusion-functions-extra/actions/workflows/ci.yml?query=branch%3Amain) | ||
<!-- [![Crates.io](https://img.shields.io/crates/v/datafusion-functions-extra?color=green)](https://crates.io/crates/datafusion-functions-extra) --> | ||
|
||
**Note:** This is not an official Apache Software Foundation release. | ||
|
||
This crate provides extra functions for DataFusion, specifically focusing on advanced aggregations. These extensions are inspired by other projects like DuckDB and Spark SQL. | ||
|
||
To use these functions, you'll just need to call: | ||
|
||
```rust | ||
datafusion_functions_extra::register_all_extra_functions(&mut ctx)?; | ||
``` | ||
|
||
# Examples | ||
|
||
```sql | ||
-- Create a table with various columns containing strings, integers, floats, dates, and times | ||
CREATE TABLE test_table ( | ||
utf8_col VARCHAR, | ||
int64_col INT, | ||
float64_col FLOAT, | ||
date64_col DATE, | ||
time64_col TIME | ||
) AS VALUES | ||
('apple', 1, 1.0, '2021-01-01', '01:00:00'), | ||
('banana', 2, 2.0, '2021-01-02', '02:00:00'), | ||
('apple', 2, 2.0, '2021-01-02', '02:00:00'), | ||
('orange', 3, 3.0, '2021-01-03', '03:00:00'), | ||
('banana', 3, 3.0, '2021-01-03', '03:00:00'), | ||
('apple', 3, 3.0, '2021-01-03', '03:00:00'); | ||
|
||
-- Get the mode of the utf8_col column | ||
SELECT mode(utf8_col) as mode_utf8 FROM test_table; | ||
-- Results in | ||
-- +----------+ | ||
-- | mode_utf8| | ||
-- +----------+ | ||
-- | apple | | ||
-- +----------+ | ||
|
||
-- Get the mode of the date64_col column | ||
SELECT mode(date64_col) as mode_date FROM test_table; | ||
-- Results in | ||
-- +-----------+ | ||
-- | mode_date | | ||
-- +-----------+ | ||
-- | 2021-01-03| | ||
-- +-----------+ | ||
|
||
-- Get the mode of the time64_col column | ||
SELECT mode(time64_col) as mode_time FROM test_table; | ||
-- Results in | ||
-- +-----------+ | ||
-- | mode_time | | ||
-- +-----------+ | ||
-- | 03:00:00 | | ||
-- +-----------+ | ||
``` | ||
|
||
## Done | ||
|
||
* [x] `mode(expression) -> scalar` - Returns the most frequent (mode) value from a column of data. |
Oops, something went wrong.