From ac7c648dc45eada3c86a872ffb59a0bfef124b10 Mon Sep 17 00:00:00 2001 From: yl790 Date: Sun, 14 Jun 2020 19:27:20 +0000 Subject: [PATCH] TimeSeriesRDDBuilder Signed-off-by: yl790 --- .../flint/annotation/SparklyrApi.java | 24 +++++++++++ .../timeseries/TimeSeriesRDDBuilder.scala | 42 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/main/scala/com/twosigma/flint/annotation/SparklyrApi.java create mode 100644 src/main/scala/com/twosigma/flint/timeseries/TimeSeriesRDDBuilder.scala diff --git a/src/main/scala/com/twosigma/flint/annotation/SparklyrApi.java b/src/main/scala/com/twosigma/flint/annotation/SparklyrApi.java new file mode 100644 index 00000000..4e28413e --- /dev/null +++ b/src/main/scala/com/twosigma/flint/annotation/SparklyrApi.java @@ -0,0 +1,24 @@ +/* + * Licensed 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. + */ + +package com.twosigma.flint.annotation; + +/** + * API for sparklyr.flint + */ +public @interface SparklyrApi { + String message() default ""; + + String until() default ""; +} diff --git a/src/main/scala/com/twosigma/flint/timeseries/TimeSeriesRDDBuilder.scala b/src/main/scala/com/twosigma/flint/timeseries/TimeSeriesRDDBuilder.scala new file mode 100644 index 00000000..1d8b5cbe --- /dev/null +++ b/src/main/scala/com/twosigma/flint/timeseries/TimeSeriesRDDBuilder.scala @@ -0,0 +1,42 @@ +/* + * Licensed 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. + */ + +package com.twosigma.flint.timeseries + +import java.util.concurrent.TimeUnit + +import com.twosigma.flint.annotation.SparklyrApi +import org.apache.spark.rdd.RDD +import org.apache.spark.sql._ +import org.apache.spark.sql.types._ + +@SparklyrApi +class TimeSeriesRDDBuilder( + isSorted: Boolean, + timeUnit: TimeUnit, + timeColumn: String +) { + def fromRDD( + rdd: RDD[Row], + schema: StructType + ): TimeSeriesRDD = { + TimeSeriesRDD.fromRDD(rdd, schema)(isSorted, timeUnit, timeColumn) + } + + def fromDF( + dataFrame: DataFrame + ): TimeSeriesRDD = { + TimeSeriesRDD.fromDF(dataFrame)(isSorted, timeUnit, timeColumn) + } +}