Skip to content

Commit

Permalink
Adding studentt_cdf UDF (GoogleCloudPlatform#421)
Browse files Browse the repository at this point in the history
* Adding studentt_cdf udf

* Fixed argument types

* Fixed sample number values

* Removed formatting changes
  • Loading branch information
dqmis authored Jun 7, 2024
1 parent 5f20e54 commit 855373f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
19 changes: 19 additions & 0 deletions udfs/community/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ SELECT bqutil.fn.int(1.684)
* [random_int](#random_intmin-any-type-max-any-type)
* [random_string](#random_stringlength-int64)
* [random_value](#random_valuearr-any-type)
* [studentt_cdf](#studentt_cdfx-float64-dof-float64)
* [sure_cond](#sure_cond)
* [sure_like](#sure_like)
* [sure_nonnull](#sure_nonnull)
Expand Down Expand Up @@ -2356,3 +2357,21 @@ Results:
| Row | normal_cdf |
|-----|-------------------|
| 1 | 0.3820885778110474 |
---
### [studentt_cdf(x FLOAT64, dof FLOAT64)](studentt_cdf.sqlx)
Returns the value of x in the cdf of the Student's T distribution with dof degrees of freedom.
Sample Query:
```SQL
SELECT `bqutils.fn.studentt_cdf`(1.0, 2.0) as studentt_cdf;
```
Results:
| Row | studentt_cdf |
| --- | ----------------- |
| 1 | 0.788675134594813 |
28 changes: 28 additions & 0 deletions udfs/community/studentt_cdf.sqlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
config { hasOutput: true }

/*
* Copyright 2021 Google LLC
*
* Licensed 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.
*/


CREATE OR REPLACE FUNCTION ${self()}(x FLOAT64, dof FLOAT64)
RETURNS FLOAT64
LANGUAGE js AS """
return jstat['jStat']['studentt']['cdf']( x, dof )
"""
OPTIONS (
library=["${JS_BUCKET}/jstat-v1.9.4.min.js"]
);

9 changes: 9 additions & 0 deletions udfs/community/test_cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,15 @@ generate_udf_test("normal_cdf", [
expected_output: `CAST(0.3820885778110474 AS FLOAT64)`
},
]);
generate_udf_test("studentt_cdf", [
{
inputs: [
`CAST(1.0 AS FLOAT64)`,
`CAST(2.0 AS FLOAT64)`
],
expected_output: `CAST(0.788675134594813 AS FLOAT64)`
},
]);
//
// End of StatsLib work tests
//
Expand Down

0 comments on commit 855373f

Please sign in to comment.