You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by ze...@apache.org on 2026/09/08 17:52:39 UTC

(iceberg-go) branch main updated: chore: dedup floorDiv (#1998)

This is an automated email from the ASF dual-hosted git repository.

zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git


The following commit(s) were added to refs/heads/main by this push:
     new 2d02b5645 chore: dedup floorDiv (#1998)
2d02b5645 is described below

commit 2d02b56454fd6d4aaa3621fae0a5493312a57502
Author: Ferhat Elmas <el...@gmail.com>
AuthorDate: Tue Sep 8 19:52:33 2026 +0200

    chore: dedup floorDiv (#1998)
    
    related to #1607
    
    Signed-off-by: Ferhat Elmas <el...@gmail.com>
---
 variant_cast.go | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/variant_cast.go b/variant_cast.go
index 93be84df9..cabf44bc2 100644
--- a/variant_cast.go
+++ b/variant_cast.go
@@ -22,6 +22,7 @@ import (
 	"github.com/apache/arrow-go/v18/arrow/decimal"
 	"github.com/apache/arrow-go/v18/arrow/decimal128"
 	"github.com/apache/arrow-go/v18/parquet/variant"
+	"github.com/apache/iceberg-go/internal"
 	"github.com/google/uuid"
 )
 
@@ -200,7 +201,7 @@ func castVariantDecimal(raw any, typ DecimalType) (any, bool) {
 func castVariantToMicros(pt variant.Type, raw any, tz bool) (any, bool) {
 	switch {
 	case tz && pt == variant.TimestampNanos, !tz && pt == variant.TimestampNanosNTZ:
-		return Timestamp(floorDiv(int64(raw.(arrow.Timestamp)), nanosPerMicro)), true
+		return Timestamp(internal.FloorDiv(int64(raw.(arrow.Timestamp)), nanosPerMicro)), true
 	case !tz && pt == variant.Date:
 		if micros, ok := mulNoOverflow(int64(raw.(arrow.Date32)), microsPerDay); ok {
 			return Timestamp(micros), true
@@ -230,24 +231,14 @@ func castVariantToNanos(pt variant.Type, raw any, tz bool) (any, bool) {
 func castVariantToDate(pt variant.Type, raw any) (any, bool) {
 	switch pt {
 	case variant.TimestampMicrosNTZ:
-		return Date(floorDiv(int64(raw.(arrow.Timestamp)), microsPerDay)), true
+		return Date(internal.FloorDiv(int64(raw.(arrow.Timestamp)), microsPerDay)), true
 	case variant.TimestampNanosNTZ:
-		return Date(floorDiv(int64(raw.(arrow.Timestamp)), nanosPerDay)), true
+		return Date(internal.FloorDiv(int64(raw.(arrow.Timestamp)), nanosPerDay)), true
 	}
 
 	return nil, false
 }
 
-// floorDiv divides rounding toward negative infinity.
-func floorDiv(a, b int64) int64 {
-	q := a / b
-	if (a%b != 0) && ((a < 0) != (b < 0)) {
-		q--
-	}
-
-	return q
-}
-
 // mulNoOverflow returns a*b, reporting false if the product overflows int64.
 func mulNoOverflow(a, b int64) (int64, bool) {
 	p := a * b