mirror of https://github.com/apache/druid.git
support radians and degrees in sql (#7336)
* support radians and degrees in sql * update test case
This commit is contained in:
parent
134f71d1b4
commit
78fd5aff21
|
@ -162,6 +162,8 @@ Numeric functions will return 64 bit integers or 64 bit floats, depending on the
|
|||
|`ACOS(expr)`|Arc cosine of expr.|
|
||||
|`ATAN(expr)`|Arc tangent of expr.|
|
||||
|`ATAN2(y, x)`|Angle theta from the conversion of rectangular coordinates (x, y) to polar * coordinates (r, theta).|
|
||||
|`DEGREES(expr)`|Converts an angle measured in radians to an approximately equivalent angle measured in degrees|
|
||||
|`RADIANS(expr)`|Converts an angle measured in degrees to an approximately equivalent angle measured in radians|
|
||||
|
||||
### String functions
|
||||
|
||||
|
|
|
@ -131,6 +131,8 @@ public class DruidOperatorTable implements SqlOperatorTable
|
|||
.add(new DirectOperatorConversion(SqlStdOperatorTable.ACOS, "acos"))
|
||||
.add(new DirectOperatorConversion(SqlStdOperatorTable.ATAN, "atan"))
|
||||
.add(new DirectOperatorConversion(SqlStdOperatorTable.ATAN2, "atan2"))
|
||||
.add(new DirectOperatorConversion(SqlStdOperatorTable.RADIANS, "toRadians"))
|
||||
.add(new DirectOperatorConversion(SqlStdOperatorTable.DEGREES, "toDegrees"))
|
||||
.add(new UnaryPrefixOperatorConversion(SqlStdOperatorTable.NOT, "!"))
|
||||
.add(new UnaryPrefixOperatorConversion(SqlStdOperatorTable.UNARY_MINUS, "-"))
|
||||
.add(new UnaryFunctionOperatorConversion(SqlStdOperatorTable.IS_NULL, "isnull"))
|
||||
|
|
|
@ -7669,4 +7669,28 @@ public class CalciteQueryTest extends BaseCalciteQueryTest
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRadiansAndDegrees() throws Exception
|
||||
{
|
||||
testQuery(
|
||||
"SELECT RADIANS(m1 * 15)/DEGREES(m2) FROM numfoo WHERE dim1 = '1'",
|
||||
ImmutableList.of(
|
||||
newScanQueryBuilder()
|
||||
.dataSource(CalciteTests.DATASOURCE3)
|
||||
.intervals(querySegmentSpec(Filtration.eternity()))
|
||||
.virtualColumns(
|
||||
expressionVirtualColumn("v0", "(toRadians((\"m1\" * 15)) / toDegrees(\"m2\"))", ValueType.DOUBLE)
|
||||
)
|
||||
.columns("v0")
|
||||
.filters(selector("dim1", "1", null))
|
||||
.resultFormat(ScanQuery.RESULT_FORMAT_COMPACTED_LIST)
|
||||
.context(QUERY_CONTEXT_DEFAULT)
|
||||
.build()
|
||||
),
|
||||
ImmutableList.of(
|
||||
new Object[]{Math.toRadians(60) / Math.toDegrees(4)}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue