sarankk commented on code in PR #155:
URL: 
https://github.com/apache/cassandra-analytics/pull/155#discussion_r2539308668


##########
cassandra-analytics-common/src/main/java/org/apache/cassandra/spark/sparksql/filters/TimeRangeFilter.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.cassandra.spark.sparksql.filters;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+import com.google.common.collect.Range;
+
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * {@link TimeRangeFilter} to filter out based on timestamp.
+ * Uses Google Guava's Range internally for storing time range.
+ */
+public final class TimeRangeFilter implements Serializable
+{
+    private final Range<Long> timeRange;
+
+    /**
+     * Creates a {@link TimeRangeFilter} with given time {@link Range}
+     */
+    private TimeRangeFilter(Range<Long> timeRange)
+    {
+        this.timeRange = timeRange;
+    }
+
+    /**
+     * Returns the underlying Range.
+     *
+     * @return the time range
+     */
+    @NotNull
+    public Range<Long> range()
+    {
+        return timeRange;
+    }
+
+    /**
+     * Determines if given start and end timestamp match the filter. SSTable 
is included if it overlaps with
+     * filter time range.
+     *
+     * @param givenStart the SSTable min timestamp
+     * @param givenEnd the SSTable max timestamp
+     * @return true if the SSTable should be included, false if it should be 
omitted.
+     */
+    public boolean filter(long givenStart, long givenEnd)
+    {
+        // Create range for the given SSTable timestamps, always closed
+        Range<Long> sstableTimeRange = Range.closed(givenStart, givenEnd);
+
+        // Check if ranges are connected (overlap or adjacent)
+        return timeRange.isConnected(sstableTimeRange) && 
!timeRange.intersection(sstableTimeRange).isEmpty();
+    }
+
+    @Override
+    public String toString()
+    {
+        return String.format("TimeRangeFilter%s", timeRange.toString());
+    }
+
+    @Override
+    public boolean equals(Object o)
+    {
+        if (this == o)
+        {
+            return true;
+        }
+        if (!(o instanceof TimeRangeFilter))
+        {
+            return false;
+        }
+        TimeRangeFilter that = (TimeRangeFilter) o;
+        return timeRange.equals(that.timeRange);
+    }
+
+    @Override
+    public int hashCode()
+    {
+        return Objects.hash(timeRange);
+    }
+
+    /**
+     * Creates a {@link TimeRangeFilter} with only start bound.
+     *
+     * @param startTimestampMicros the start timestamp in microseconds 
(inclusive)
+     * @return {@link TimeRangeFilter} with only start timestamp
+     */
+    @NotNull
+    public static TimeRangeFilter startingAt(long startTimestampMicros)

Review Comment:
   This filter can be used for other time range, for SSTable overlap we want 
only microseconds. I will remove microseconds from filter class and add the 
documentation to spark options and overlap method. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to