-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93dba5d
commit 6fff6fe
Showing
5 changed files
with
184 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package parquet | ||
|
||
import ( | ||
"github.com/apache/arrow/go/v13/arrow" | ||
"github.com/apache/arrow/go/v13/arrow/array" | ||
"github.com/apache/arrow/go/v13/arrow/memory" | ||
) | ||
|
||
func reverseTransformDate32(arr *array.Timestamp, toTime toTimeFunc) arrow.Array { | ||
builder := array.NewDate32Builder(memory.DefaultAllocator) | ||
|
||
for i := 0; i < arr.Len(); i++ { | ||
if arr.IsNull(i) { | ||
builder.AppendNull() | ||
continue | ||
} | ||
|
||
builder.Append(arrow.Date32FromTime(toTime(arr.Value(i)))) | ||
} | ||
|
||
return builder.NewArray() | ||
} | ||
|
||
func reverseTransformDate64(arr *array.Timestamp, toTime toTimeFunc) arrow.Array { | ||
builder := array.NewDate64Builder(memory.DefaultAllocator) | ||
|
||
for i := 0; i < arr.Len(); i++ { | ||
if arr.IsNull(i) { | ||
builder.AppendNull() | ||
continue | ||
} | ||
|
||
builder.Append(arrow.Date64FromTime(toTime(arr.Value(i)))) | ||
} | ||
|
||
return builder.NewArray() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package parquet | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/apache/arrow/go/v13/arrow" | ||
"github.com/apache/arrow/go/v13/arrow/array" | ||
"github.com/apache/arrow/go/v13/arrow/memory" | ||
) | ||
|
||
type toTimeFunc func(arrow.Timestamp) time.Time | ||
|
||
func reverseTransformTime32(dt *arrow.Time32Type, arr *array.Time32) arrow.Array { | ||
builder := array.NewTime32Builder(memory.DefaultAllocator, dt) | ||
|
||
rescale := func() func(t arrow.Time32) arrow.Time32 { | ||
switch arr.DataType().(*arrow.Time32Type).Unit { | ||
case arrow.Second: | ||
switch dt.Unit { | ||
case arrow.Second: | ||
return func(t arrow.Time32) arrow.Time32 { return t } | ||
case arrow.Millisecond: | ||
return func(t arrow.Time32) arrow.Time32 { return t * 1e3 } | ||
default: | ||
panic("unsupported time32 time unit: " + dt.Unit.String()) | ||
} | ||
case arrow.Millisecond: | ||
switch dt.Unit { | ||
case arrow.Second: | ||
return func(t arrow.Time32) arrow.Time32 { return t / 1e3 } | ||
case arrow.Millisecond: | ||
return func(t arrow.Time32) arrow.Time32 { return t } | ||
default: | ||
panic("unsupported time32 time unit: " + dt.Unit.String()) | ||
} | ||
default: | ||
panic("unsupported time32 time unit: " + arr.DataType().(*arrow.Time32Type).Unit.String()) | ||
} | ||
}() | ||
|
||
for i := 0; i < arr.Len(); i++ { | ||
if arr.IsNull(i) { | ||
builder.AppendNull() | ||
continue | ||
} | ||
|
||
builder.Append(rescale(arr.Value(i))) | ||
} | ||
|
||
return builder.NewArray() | ||
} | ||
|
||
func reverseTransformTime64(dt *arrow.Time64Type, arr *array.Time64) arrow.Array { | ||
builder := array.NewTime64Builder(memory.DefaultAllocator, dt) | ||
|
||
rescale := func() func(t arrow.Time64) arrow.Time64 { | ||
switch arr.DataType().(*arrow.Time64Type).Unit { | ||
case arrow.Microsecond: | ||
switch dt.Unit { | ||
case arrow.Microsecond: | ||
return func(t arrow.Time64) arrow.Time64 { return t } | ||
case arrow.Nanosecond: | ||
return func(t arrow.Time64) arrow.Time64 { return t * 1e3 } | ||
default: | ||
panic("unsupported time64 time unit: " + dt.Unit.String()) | ||
} | ||
case arrow.Nanosecond: | ||
switch dt.Unit { | ||
case arrow.Microsecond: | ||
return func(t arrow.Time64) arrow.Time64 { return t / 1e3 } | ||
case arrow.Nanosecond: | ||
return func(t arrow.Time64) arrow.Time64 { return t } | ||
default: | ||
panic("unsupported time64 time unit: " + dt.Unit.String()) | ||
} | ||
default: | ||
panic("unsupported time64 time unit: " + arr.DataType().(*arrow.Time64Type).Unit.String()) | ||
} | ||
}() | ||
|
||
for i := 0; i < arr.Len(); i++ { | ||
if arr.IsNull(i) { | ||
builder.AppendNull() | ||
continue | ||
} | ||
|
||
builder.Append(rescale(arr.Value(i))) | ||
} | ||
|
||
return builder.NewArray() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package parquet | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/apache/arrow/go/v13/arrow" | ||
"github.com/apache/arrow/go/v13/arrow/array" | ||
"github.com/apache/arrow/go/v13/arrow/memory" | ||
) | ||
|
||
func reverseTransformTimestamp(dt *arrow.TimestampType, arr *array.Timestamp) arrow.Array { | ||
builder := array.NewTimestampBuilder(memory.DefaultAllocator, dt) | ||
in, out := arr.DataType().(*arrow.TimestampType).Unit, dt.Unit | ||
|
||
for i := 0; i < arr.Len(); i++ { | ||
if arr.IsNull(i) { | ||
builder.AppendNull() | ||
continue | ||
} | ||
|
||
builder.Append(arrow.Timestamp(arrow.ConvertTimestampValue(in, out, int64(arr.Value(i))))) | ||
} | ||
|
||
return builder.NewArray() | ||
} | ||
|
||
func reverseTransformFromTimestamp(dt arrow.DataType, arr *array.Timestamp) arrow.Array { | ||
toTime, err := arr.DataType().(*arrow.TimestampType).GetToTimeFunc() | ||
if err != nil { | ||
panic(fmt.Errorf("failed GetToTimeFunc: %w", err)) | ||
} | ||
|
||
switch dt := dt.(type) { | ||
case *arrow.Date32Type: | ||
return reverseTransformDate32(arr, toTime) | ||
case *arrow.Date64Type: | ||
return reverseTransformDate64(arr, toTime) | ||
case *arrow.TimestampType: | ||
return reverseTransformTimestamp(dt, arr) | ||
default: | ||
return reverseTransformFromString(dt, arr) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters