Skip to content
Reference > Prepare Methods

resample(x,y,xq,linearOrSpline)

Definition

Object resample(Number x, Number y, Number xq, String linearOrSpline)

Description

Resample y to new x values using linear or spline approximation

Parameter Definition

Name Type Description
x Number
y Number
xq Number
linearOrSpline String

Example 1

CREATE TABLE input(symbol String, x int, y int);
INSERT INTO input VALUES ("CAT", 1, 2),("CAT", 3, 4),("CAT", 5, 10),("CAT", 7, 1),("CAT", 9, 20);
INSERT INTO input VALUES ("IBM", 1, 4),("IBM", 3, 6),("IBM", 5, 9),("IBM", 7, 2),("IBM", 9, 30);
CREATE TABLE result AS PREPARE *,x+1 as new_x, resample(x,y,x+1,"linear") as new_y_linear, resample(x,y,x+1,"spline") as new_y_spline from input PARTITION BY symbol;
Table input = SELECT * FROM input;
TABLE result = SELECT * FROM result;

// input = 
// +----------------------+
// |        input         |
// +------+-------+-------+
// |symbol|x      |y      |
// |String|Integer|Integer|
// +------+-------+-------+
// |CAT   |1      |2      |
// |CAT   |3      |4      |
// |CAT   |5      |10     |
// |CAT   |7      |1      |
// |CAT   |9      |20     |
// |IBM   |1      |4      |
// |IBM   |3      |6      |
// |IBM   |5      |9      |
// |IBM   |7      |2      |
// |IBM   |9      |30     |
// +------+-------+-------+
// 
// result = 
// +-------------------------------------------------------------+
// |                           result                            |
// +------+-------+-------+-------+------------+-----------------+
// |symbol|x      |y      |new_x  |new_y_linear|new_y_spline     |
// |String|Integer|Integer|Integer|Double      |Double           |
// +------+-------+-------+-------+------------+-----------------+
// |CAT   |1      |2      |2      |3.0         |0.34375          |
// |CAT   |3      |4      |4      |7.0         |8.65625          |
// |CAT   |5      |10     |6      |5.5         |5.65625          |
// |CAT   |7      |1      |8      |10.5        |3.34375          |
// |CAT   |9      |20     |10     |29.5        |58.28125         |
// |IBM   |1      |4      |2      |5.0         |3.312499999999993|
// |IBM   |3      |6      |4      |7.5         |8.937500000000007|
// |IBM   |5      |9      |6      |5.5         |4.8125           |
// |IBM   |7      |2      |8      |16.0        |7.9375           |
// |IBM   |9      |30     |10     |44.0        |75.5625          |
// +------+-------+-------+-------+------------+-----------------+
//