Skip to content

Commit

Permalink
[CI][JS] Update code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
handstuyennn committed Sep 4, 2024
1 parent 1715599 commit 4655859
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion js/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ export class IntervalDayTime extends Interval_<Type.IntervalDayTime> { construct
/** @ignore */
export class IntervalYearMonth extends Interval_<Type.IntervalYearMonth> { constructor() { super(IntervalUnit.YEAR_MONTH); } }
/** @ignore */
export class IntervalMonthDayNano extends Interval_<Type.IntervalMonthDayNano> { constructor() { super(IntervalUnit.MONTH_DAY_NANO) } }
export class IntervalMonthDayNano extends Interval_<Type.IntervalMonthDayNano> { constructor() { super(IntervalUnit.MONTH_DAY_NANO); } }

/** @ignore */
type Durations = Type.Duration | Type.DurationSecond | Type.DurationMillisecond | Type.DurationMicrosecond | Type.DurationNanosecond;
Expand Down
37 changes: 26 additions & 11 deletions js/test/unit/vector/interval-month-day-nano-tests.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import { IntervalMonthDayNano, Vector, makeData } from "apache-arrow";
// 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.

import { IntervalMonthDayNano, Vector, makeData } from 'apache-arrow';

type IntervalValue = {
months?: number;
days?: number;
nanoseconds?: bigint
nanoseconds?: bigint;
};

function formatIntervalValue(value: IntervalValue): IntervalValue {
Expand All @@ -13,19 +30,15 @@ function formatIntervalValue(value: IntervalValue): IntervalValue {
function convertIntervalValueToIntArray(value: IntervalValue): Int32Array {
const int64s = new BigInt64Array(2);
int64s[0] = BigInt(value.months ?? 0) + BigInt(value.days ?? 0) * (BigInt(1) << BigInt(32));
if (value.nanoseconds) {
int64s[1] = value.nanoseconds;
} else {
int64s[1] = BigInt(0);
}
int64s[1] = value.nanoseconds ? value.nanoseconds : BigInt(0);
return new Int32Array(int64s.buffer);
}

function convertIntArrayToIntervalValue(value: Int32Array | null): IntervalValue | null {
if (!value) return null;
const intervalValue: IntervalValue = {};
intervalValue.months = value[0];
const negative = value[1] & (1 << 31)
const negative = value[1] & (1 << 31);
intervalValue.days = value[1] + (negative ? 1 : 0);
const secondWords = new BigInt64Array(value.buffer);
intervalValue.nanoseconds = secondWords[1];
Expand All @@ -36,9 +49,11 @@ function makeIntervalMonthDayNanoVector(intervalArray: IntervalValue[]) {
const type = new IntervalMonthDayNano();
const length = intervalArray.length;
const data = new Int32Array(length * 4);
for (let i = 0; i < intervalArray.length; i++) {
const intervalLength = intervalArray.length
for (let i = 0; i < intervalLength; i++) {
const intValue = convertIntervalValueToIntArray(intervalArray[i]);
for (let j = 0; j < intValue.length; j++) {
const intLength = intValue.length;
for (let j = 0; j < intLength; j++) {
data[i * 4 + j] = intValue[j];
}
}
Expand Down Expand Up @@ -81,4 +96,4 @@ describe(`MonthDayNanoInteralVector`, () => {
expect(vec.type).toBeInstanceOf(IntervalMonthDayNano);
expect(convertIntArrayToIntervalValue(vec.get(0))).toStrictEqual(value);
});
});
});

0 comments on commit 4655859

Please sign in to comment.