| /* ----------------------------------------------------------------------- *//** |
| * |
| * 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. |
| * |
| *//* ----------------------------------------------------------------------- */ |
| --------------------------------------------------------------------------- |
| -- Rules: |
| -- ------ |
| -- 1) Any DB objects should be created w/o schema prefix, |
| -- since this file is executed in a separate schema context. |
| -- 2) There should be no DROP statements in this script, since |
| -- all objects created in the default schema will be cleaned-up outside. |
| --------------------------------------------------------------------------- |
| |
| --------------------------------------------------------------------------- |
| -- Setup: |
| --------------------------------------------------------------------------- |
| CREATE TABLE data AS |
| SELECT |
| '{1,2,3}'::float8[] AS an, |
| '{4,5,7}'::float8[] AS b; |
| |
| SELECT MADLIB_SCHEMA.array_dot( |
| MADLIB_SCHEMA.array_mult( |
| MADLIB_SCHEMA.array_add(an,b), |
| MADLIB_SCHEMA.array_sub(an,b)), |
| MADLIB_SCHEMA.array_mult( |
| MADLIB_SCHEMA.array_div(an,b), |
| MADLIB_SCHEMA.normalize(an))) AS result1 |
| FROM data; |
| |
| SELECT MADLIB_SCHEMA.array_max(b) FROM data; |
| SELECT MADLIB_SCHEMA.array_min(b) FROM data; |
| SELECT MADLIB_SCHEMA.array_sum(b) FROM data; |
| SELECT MADLIB_SCHEMA.array_sum_big(b) FROM data; |
| SELECT MADLIB_SCHEMA.array_mean(b) FROM data; |
| SELECT MADLIB_SCHEMA.array_stddev(b) FROM data; |
| |
| SELECT MADLIB_SCHEMA.array_scalar_mult( |
| MADLIB_SCHEMA.array_fill( |
| MADLIB_SCHEMA.array_of_float(20), |
| 234.343::FLOAT8), |
| 3.7::FLOAT8) |
| FROM data; |
| |
| SELECT MADLIB_SCHEMA.array_filter(ARRAY[0.8, 9.5, 0, 2.6]::float8[]); |
| SELECT MADLIB_SCHEMA.array_filter(ARRAY[0.8, 9.5, 0, 2.6]::float8[], 2.5::float8, '<'); |
| |
| -------------------------------------------------------------- |
| -- TESTING array_unnest_2d_to_1d FUNCTION |
| -------------------------------------------------------------- |
| -- 2-element float8 arrays |
| DROP TABLE IF EXISTS unnest_2d_tbl01; |
| CREATE TABLE unnest_2d_tbl01 (id INT, val DOUBLE PRECISION[][]); |
| INSERT INTO unnest_2d_tbl01 VALUES |
| (1, ARRAY[[1::float8,2],[3::float8,4],[5::float8,6]]), |
| (2, ARRAY[[101::float8,202],[303::float8,404],[505::float8,606]]) |
| ; |
| |
| DROP TABLE IF EXISTS unnest_2d_tbl01_out; |
| CREATE TABLE unnest_2d_tbl01_out AS |
| SELECT id, (MADLIB_SCHEMA.array_unnest_2d_to_1d(val)).* FROM unnest_2d_tbl01; |