Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
import static org.opensearch.sql.expression.function.BuiltinFunctionName.SUM;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.SYSDATE;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.TAKE;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.TAN;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.TIME;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.TIMEDIFF;
import static org.opensearch.sql.expression.function.BuiltinFunctionName.TIMESTAMP;
Expand Down Expand Up @@ -1080,6 +1081,7 @@ void populate() {
registerOperator(SIGN, SqlStdOperatorTable.SIGN);
registerOperator(SIGNUM, SqlStdOperatorTable.SIGN);
registerOperator(SIN, SqlStdOperatorTable.SIN);
registerOperator(TAN, SqlStdOperatorTable.TAN);
registerOperator(CBRT, SqlStdOperatorTable.CBRT);

registerOperator(IFNULL, SqlStdOperatorTable.COALESCE);
Expand Down
32 changes: 31 additions & 1 deletion docs/user/ppl/functions/math.md
Original file line number Diff line number Diff line change
Expand Up @@ -1425,4 +1425,34 @@ fetched rows / total rows = 1/1
| 2.0 |
+-----------+
```


## TAN

**Usage**: `TAN(x)`

Calculates the tangent of `x`, where `x` is given in radians.

**Parameters**:

- `x` (Required): An `INTEGER`, `LONG`, `FLOAT`, or `DOUBLE` value.

**Return type**: `DOUBLE`

### Example

```ppl
source=people
| eval `TAN(0)` = TAN(0)
| fields `TAN(0)`
```

The query returns the following results:

```text
fetched rows / total rows = 1/1
+--------+
| TAN(0) |
|--------|
| 0.0 |
+--------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ public void testPiAndCot() throws IOException {
verifyDataRows(actual, closeTo(1.0));
}

@Test
public void testTan() throws IOException {
JSONObject actual =
executeQuery(
String.format(
"source=%s | eval tan = tan(pi() / 4) | head 1 | fields tan",
TEST_INDEX_STATE_COUNTRY));

verifySchema(actual, schema("tan", "double"));
verifyDataRows(actual, closeTo(1.0));
}

@Test
public void testCrc32AndAbs() throws IOException {
JSONObject actual =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,11 @@ public void testSqrt() {
String expectedSparkSql = "SELECT POWER(4, 5E-1) `SQRT`\nFROM `scott`.`EMP`";
verifyPPLToSparkSQL(root, expectedSparkSql);
}

@Test
public void testTan() {
withPPLQuery("source=EMP | eval TAN = tan(0) | fields TAN")
.expectLogical("LogicalProject(TAN=[TAN(0)])\n LogicalTableScan(table=[[scott, EMP]])\n")
.expectSparkSQL("SELECT TAN(0) `TAN`\nFROM `scott`.`EMP`");
}
}
Loading