support radians and degrees in sql (#7336)

* support radians and degrees in sql

* update test case
This commit is contained in:
Xue Yu 2019-04-03 03:47:49 +08:00 committed by Clint Wylie
parent 134f71d1b4
commit 78fd5aff21
3 changed files with 28 additions and 0 deletions

View File

@ -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

View File

@ -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"))

View File

@ -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)}
)
);
}
}