Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 203 additions & 0 deletions c_glib/arrow-glib/compute.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -254,6 +254,10 @@ G_BEGIN_DECLS
* #GArrowAssumeTimezoneOptions is a class to customize the `assume_timezone`
* function.
*
* #GArrowCumulativeOptions is a class to customize the cumulative functions
* such as `cumulative_sum`, `cumulative_prod`, `cumulative_max`, and
* `cumulative_min`.
*
* There are many functions to compute data on an array.
*/

Expand DownExpand Up@@ -6491,6 +6495,173 @@ garrow_assume_timezone_options_new(void)
return GARROW_ASSUME_TIMEZONE_OPTIONS(options);
}

typedef struct GArrowCumulativeOptionsPrivate_
{
GArrowScalar *start;
} GArrowCumulativeOptionsPrivate;

enum {
PROP_CUMULATIVE_OPTIONS_START = 1,
PROP_CUMULATIVE_OPTIONS_SKIP_NULLS,
};

G_DEFINE_TYPE_WITH_PRIVATE(GArrowCumulativeOptions,
garrow_cumulative_options,
GARROW_TYPE_FUNCTION_OPTIONS)

#define GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object) \
static_cast<GArrowCumulativeOptionsPrivate *>( \
garrow_cumulative_options_get_instance_private(GARROW_CUMULATIVE_OPTIONS(object)))

static void
garrow_cumulative_options_dispose(GObject *object)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);

if (priv->start) {
g_object_unref(priv->start);
priv->start = nullptr;
}

G_OBJECT_CLASS(garrow_cumulative_options_parent_class)->dispose(object);
}

static void
garrow_cumulative_options_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
auto options = garrow_cumulative_options_get_raw(GARROW_CUMULATIVE_OPTIONS(object));

switch (prop_id) {
case PROP_CUMULATIVE_OPTIONS_START:
{
auto scalar = GARROW_SCALAR(g_value_get_object(value));
if (priv->start == scalar) {
return;
}
if (priv->start) {
g_object_unref(priv->start);
}
priv->start = scalar;
if (priv->start) {
g_object_ref(priv->start);
options->start = garrow_scalar_get_raw(scalar);
} else {
options->start = std::nullopt;
}
break;
}
case PROP_CUMULATIVE_OPTIONS_SKIP_NULLS:
options->skip_nulls = g_value_get_boolean(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_cumulative_options_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
auto options = garrow_cumulative_options_get_raw(GARROW_CUMULATIVE_OPTIONS(object));

switch (prop_id) {
case PROP_CUMULATIVE_OPTIONS_START:
{
if (priv->start) {
g_value_set_object(value, G_OBJECT(priv->start));
} else {
g_value_set_object(value, NULL);
}
break;
}
case PROP_CUMULATIVE_OPTIONS_SKIP_NULLS:
g_value_set_boolean(value, options->skip_nulls);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_cumulative_options_init(GArrowCumulativeOptions *object)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
priv->start = nullptr;
auto function_options_priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
function_options_priv->options = static_cast<arrow::compute::FunctionOptions *>(
new arrow::compute::CumulativeOptions());
}

static void
garrow_cumulative_options_class_init(GArrowCumulativeOptionsClass *klass)
{
auto gobject_class = G_OBJECT_CLASS(klass);

gobject_class->dispose = garrow_cumulative_options_dispose;
gobject_class->set_property = garrow_cumulative_options_set_property;
gobject_class->get_property = garrow_cumulative_options_get_property;

arrow::compute::CumulativeOptions options;

GParamSpec *spec;
/**
* GArrowCumulativeOptions:start:
*
* Optional starting value for cumulative operation computation.
*
* Since: 23.0.0
*/
spec =
g_param_spec_object("start",
"Start",
"Optional starting value for cumulative operation computation",
GARROW_TYPE_SCALAR,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class, PROP_CUMULATIVE_OPTIONS_START, spec);

/**
* GArrowCumulativeOptions:skip-nulls:
*
* If true, nulls in the input are ignored and produce a corresponding null output.
* When false, the first null encountered is propagated through the remaining output.
*
* Since: 23.0.0
*/
spec = g_param_spec_boolean(
"skip-nulls",
"Skip nulls",
"If true, nulls in the input are ignored and produce a corresponding null output. "
"When false, the first null encountered is propagated through the remaining output",
options.skip_nulls,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
PROP_CUMULATIVE_OPTIONS_SKIP_NULLS,
spec);
}

/**
* garrow_cumulative_options_new:
*
* Returns: A newly created #GArrowCumulativeOptions.
*
* Since: 23.0.0
*/
GArrowCumulativeOptions *
garrow_cumulative_options_new(void)
{
auto options = g_object_new(GARROW_TYPE_CUMULATIVE_OPTIONS, NULL);
return GARROW_CUMULATIVE_OPTIONS(options);
}

G_END_DECLS

arrow::Result<arrow::FieldRef>
Expand DownExpand Up@@ -6627,6 +6798,11 @@ garrow_function_options_new_raw(const arrow::compute::FunctionOptions *arrow_opt
static_cast<const arrow::compute::AssumeTimezoneOptions *>(arrow_options);
auto options = garrow_assume_timezone_options_new_raw(arrow_assume_timezone_options);
return GARROW_FUNCTION_OPTIONS(options);
} else if (arrow_type_name == "CumulativeOptions") {
const auto arrow_cumulative_options =
static_cast<const arrow::compute::CumulativeOptions *>(arrow_options);
auto options = garrow_cumulative_options_new_raw(arrow_cumulative_options);
return GARROW_FUNCTION_OPTIONS(options);
} else {
auto options = g_object_new(GARROW_TYPE_FUNCTION_OPTIONS, NULL);
return GARROW_FUNCTION_OPTIONS(options);
Expand DownExpand Up@@ -7167,3 +7343,30 @@ garrow_assume_timezone_options_get_raw(GArrowAssumeTimezoneOptions *options)
return static_cast<arrow::compute::AssumeTimezoneOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}

GArrowCumulativeOptions *
garrow_cumulative_options_new_raw(const arrow::compute::CumulativeOptions *arrow_options)
{
GArrowScalar *start = nullptr;
if (arrow_options->start.has_value()) {
std::shared_ptr<arrow::Scalar> arrow_start = arrow_options->start.value();
start = garrow_scalar_new_raw(&arrow_start);
}
auto options = GARROW_CUMULATIVE_OPTIONS(g_object_new(GARROW_TYPE_CUMULATIVE_OPTIONS,
"start",
start,
"skip-nulls",
arrow_options->skip_nulls,
NULL));
if (start) {
g_object_unref(start);
}
return options;
}

arrow::compute::CumulativeOptions *
garrow_cumulative_options_get_raw(GArrowCumulativeOptions *options)
{
return static_cast<arrow::compute::CumulativeOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}
16 changes: 16 additions & 0 deletions c_glib/arrow-glib/compute.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -1173,4 +1173,20 @@ GARROW_AVAILABLE_IN_23_0
GArrowAssumeTimezoneOptions *
garrow_assume_timezone_options_new(void);

#define GARROW_TYPE_CUMULATIVE_OPTIONS (garrow_cumulative_options_get_type())
GARROW_AVAILABLE_IN_23_0
G_DECLARE_DERIVABLE_TYPE(GArrowCumulativeOptions,
garrow_cumulative_options,
GARROW,
CUMULATIVE_OPTIONS,
GArrowFunctionOptions)
struct _GArrowCumulativeOptionsClass
{
GArrowFunctionOptionsClass parent_class;
};

GARROW_AVAILABLE_IN_23_0
GArrowCumulativeOptions *
garrow_cumulative_options_new(void);

G_END_DECLS
5 changes: 5 additions & 0 deletions c_glib/arrow-glib/compute.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -181,3 +181,8 @@ garrow_assume_timezone_options_new_raw(
const arrow::compute::AssumeTimezoneOptions *arrow_options);
arrow::compute::AssumeTimezoneOptions *
garrow_assume_timezone_options_get_raw(GArrowAssumeTimezoneOptions *options);

GArrowCumulativeOptions *
garrow_cumulative_options_new_raw(const arrow::compute::CumulativeOptions *arrow_options);
arrow::compute::CumulativeOptions *
garrow_cumulative_options_get_raw(GArrowCumulativeOptions *options);
64 changes: 64 additions & 0 deletions c_glib/test/test-cumulative-options.rb
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
# 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.

class TestCumulativeOptions < Test::Unit::TestCase
include Helper::Buildable

def setup
@options = Arrow::CumulativeOptions.new
end

def test_start_property
assert_nil(@options.start)
start_scalar = Arrow::Int64Scalar.new(10)
@options.start = start_scalar
assert_equal(start_scalar, @options.start)
@options.start = nil
assert_nil(@options.start)
end

def test_skip_nulls_property
assert do
!@options.skip_nulls?
end
@options.skip_nulls = true
assert do
@options.skip_nulls?
end
end

def test_cumulative_sum_with_skip_nulls
args = [
Arrow::ArrayDatum.new(build_int64_array([1, 2, 3, nil, 4, 5])),
]
@options.skip_nulls = true
cumulative_sum_function = Arrow::Function.find("cumulative_sum")
assert_equal(build_int64_array([1, 3, 6, nil, 10, 15]),
cumulative_sum_function.execute(args, @options).value)
end

def test_cumulative_sum_with_start
args = [
Arrow::ArrayDatum.new(build_int64_array([1, 2, 3])),
]
@options.start = Arrow::Int64Scalar.new(10)
cumulative_sum_function = Arrow::Function.find("cumulative_sum")
assert_equal(build_int64_array([11, 13, 16]),
cumulative_sum_function.execute(args, @options).value)
end
end

Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all \u003cpre\u003e\u003ccode\u003e blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks"); } } catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); } })(); (function(){ try { var __m = "github.com"; var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 203 additions & 0 deletions c_glib/arrow-glib/compute.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -254,6 +254,10 @@ G_BEGIN_DECLS
* #GArrowAssumeTimezoneOptions is a class to customize the `assume_timezone`
* function.
*
* #GArrowCumulativeOptions is a class to customize the cumulative functions
* such as `cumulative_sum`, `cumulative_prod`, `cumulative_max`, and
* `cumulative_min`.
*
* There are many functions to compute data on an array.
*/

Expand DownExpand Up@@ -6491,6 +6495,173 @@ garrow_assume_timezone_options_new(void)
return GARROW_ASSUME_TIMEZONE_OPTIONS(options);
}

typedef struct GArrowCumulativeOptionsPrivate_
{
GArrowScalar *start;
} GArrowCumulativeOptionsPrivate;

enum {
PROP_CUMULATIVE_OPTIONS_START = 1,
PROP_CUMULATIVE_OPTIONS_SKIP_NULLS,
};

G_DEFINE_TYPE_WITH_PRIVATE(GArrowCumulativeOptions,
garrow_cumulative_options,
GARROW_TYPE_FUNCTION_OPTIONS)

#define GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object) \
static_cast<GArrowCumulativeOptionsPrivate *>( \
garrow_cumulative_options_get_instance_private(GARROW_CUMULATIVE_OPTIONS(object)))

static void
garrow_cumulative_options_dispose(GObject *object)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);

if (priv->start) {
g_object_unref(priv->start);
priv->start = nullptr;
}

G_OBJECT_CLASS(garrow_cumulative_options_parent_class)->dispose(object);
}

static void
garrow_cumulative_options_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
auto options = garrow_cumulative_options_get_raw(GARROW_CUMULATIVE_OPTIONS(object));

switch (prop_id) {
case PROP_CUMULATIVE_OPTIONS_START:
{
auto scalar = GARROW_SCALAR(g_value_get_object(value));
if (priv->start == scalar) {
return;
}
if (priv->start) {
g_object_unref(priv->start);
}
priv->start = scalar;
if (priv->start) {
g_object_ref(priv->start);
options->start = garrow_scalar_get_raw(scalar);
} else {
options->start = std::nullopt;
}
break;
}
case PROP_CUMULATIVE_OPTIONS_SKIP_NULLS:
options->skip_nulls = g_value_get_boolean(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_cumulative_options_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
auto options = garrow_cumulative_options_get_raw(GARROW_CUMULATIVE_OPTIONS(object));

switch (prop_id) {
case PROP_CUMULATIVE_OPTIONS_START:
{
if (priv->start) {
g_value_set_object(value, G_OBJECT(priv->start));
} else {
g_value_set_object(value, NULL);
}
break;
}
case PROP_CUMULATIVE_OPTIONS_SKIP_NULLS:
g_value_set_boolean(value, options->skip_nulls);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_cumulative_options_init(GArrowCumulativeOptions *object)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
priv->start = nullptr;
auto function_options_priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
function_options_priv->options = static_cast<arrow::compute::FunctionOptions *>(
new arrow::compute::CumulativeOptions());
}

static void
garrow_cumulative_options_class_init(GArrowCumulativeOptionsClass *klass)
{
auto gobject_class = G_OBJECT_CLASS(klass);

gobject_class->dispose = garrow_cumulative_options_dispose;
gobject_class->set_property = garrow_cumulative_options_set_property;
gobject_class->get_property = garrow_cumulative_options_get_property;

arrow::compute::CumulativeOptions options;

GParamSpec *spec;
/**
* GArrowCumulativeOptions:start:
*
* Optional starting value for cumulative operation computation.
*
* Since: 23.0.0
*/
spec =
g_param_spec_object("start",
"Start",
"Optional starting value for cumulative operation computation",
GARROW_TYPE_SCALAR,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class, PROP_CUMULATIVE_OPTIONS_START, spec);

/**
* GArrowCumulativeOptions:skip-nulls:
*
* If true, nulls in the input are ignored and produce a corresponding null output.
* When false, the first null encountered is propagated through the remaining output.
*
* Since: 23.0.0
*/
spec = g_param_spec_boolean(
"skip-nulls",
"Skip nulls",
"If true, nulls in the input are ignored and produce a corresponding null output. "
"When false, the first null encountered is propagated through the remaining output",
options.skip_nulls,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
PROP_CUMULATIVE_OPTIONS_SKIP_NULLS,
spec);
}

/**
* garrow_cumulative_options_new:
*
* Returns: A newly created #GArrowCumulativeOptions.
*
* Since: 23.0.0
*/
GArrowCumulativeOptions *
garrow_cumulative_options_new(void)
{
auto options = g_object_new(GARROW_TYPE_CUMULATIVE_OPTIONS, NULL);
return GARROW_CUMULATIVE_OPTIONS(options);
}

G_END_DECLS

arrow::Result<arrow::FieldRef>
Expand DownExpand Up@@ -6627,6 +6798,11 @@ garrow_function_options_new_raw(const arrow::compute::FunctionOptions *arrow_opt
static_cast<const arrow::compute::AssumeTimezoneOptions *>(arrow_options);
auto options = garrow_assume_timezone_options_new_raw(arrow_assume_timezone_options);
return GARROW_FUNCTION_OPTIONS(options);
} else if (arrow_type_name == "CumulativeOptions") {
const auto arrow_cumulative_options =
static_cast<const arrow::compute::CumulativeOptions *>(arrow_options);
auto options = garrow_cumulative_options_new_raw(arrow_cumulative_options);
return GARROW_FUNCTION_OPTIONS(options);
} else {
auto options = g_object_new(GARROW_TYPE_FUNCTION_OPTIONS, NULL);
return GARROW_FUNCTION_OPTIONS(options);
Expand DownExpand Up@@ -7167,3 +7343,30 @@ garrow_assume_timezone_options_get_raw(GArrowAssumeTimezoneOptions *options)
return static_cast<arrow::compute::AssumeTimezoneOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}

GArrowCumulativeOptions *
garrow_cumulative_options_new_raw(const arrow::compute::CumulativeOptions *arrow_options)
{
GArrowScalar *start = nullptr;
if (arrow_options->start.has_value()) {
std::shared_ptr<arrow::Scalar> arrow_start = arrow_options->start.value();
start = garrow_scalar_new_raw(&arrow_start);
}
auto options = GARROW_CUMULATIVE_OPTIONS(g_object_new(GARROW_TYPE_CUMULATIVE_OPTIONS,
"start",
start,
"skip-nulls",
arrow_options->skip_nulls,
NULL));
if (start) {
g_object_unref(start);
}
return options;
}

arrow::compute::CumulativeOptions *
garrow_cumulative_options_get_raw(GArrowCumulativeOptions *options)
{
return static_cast<arrow::compute::CumulativeOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}
16 changes: 16 additions & 0 deletions c_glib/arrow-glib/compute.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -1173,4 +1173,20 @@ GARROW_AVAILABLE_IN_23_0
GArrowAssumeTimezoneOptions *
garrow_assume_timezone_options_new(void);

#define GARROW_TYPE_CUMULATIVE_OPTIONS (garrow_cumulative_options_get_type())
GARROW_AVAILABLE_IN_23_0
G_DECLARE_DERIVABLE_TYPE(GArrowCumulativeOptions,
garrow_cumulative_options,
GARROW,
CUMULATIVE_OPTIONS,
GArrowFunctionOptions)
struct _GArrowCumulativeOptionsClass
{
GArrowFunctionOptionsClass parent_class;
};

GARROW_AVAILABLE_IN_23_0
GArrowCumulativeOptions *
garrow_cumulative_options_new(void);

G_END_DECLS
5 changes: 5 additions & 0 deletions c_glib/arrow-glib/compute.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -181,3 +181,8 @@ garrow_assume_timezone_options_new_raw(
const arrow::compute::AssumeTimezoneOptions *arrow_options);
arrow::compute::AssumeTimezoneOptions *
garrow_assume_timezone_options_get_raw(GArrowAssumeTimezoneOptions *options);

GArrowCumulativeOptions *
garrow_cumulative_options_new_raw(const arrow::compute::CumulativeOptions *arrow_options);
arrow::compute::CumulativeOptions *
garrow_cumulative_options_get_raw(GArrowCumulativeOptions *options);
64 changes: 64 additions & 0 deletions c_glib/test/test-cumulative-options.rb
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
# 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.

class TestCumulativeOptions < Test::Unit::TestCase
include Helper::Buildable

def setup
@options = Arrow::CumulativeOptions.new
end

def test_start_property
assert_nil(@options.start)
start_scalar = Arrow::Int64Scalar.new(10)
@options.start = start_scalar
assert_equal(start_scalar, @options.start)
@options.start = nil
assert_nil(@options.start)
end

def test_skip_nulls_property
assert do
!@options.skip_nulls?
end
@options.skip_nulls = true
assert do
@options.skip_nulls?
end
end

def test_cumulative_sum_with_skip_nulls
args = [
Arrow::ArrayDatum.new(build_int64_array([1, 2, 3, nil, 4, 5])),
]
@options.skip_nulls = true
cumulative_sum_function = Arrow::Function.find("cumulative_sum")
assert_equal(build_int64_array([1, 3, 6, nil, 10, 15]),
cumulative_sum_function.execute(args, @options).value)
end

def test_cumulative_sum_with_start
args = [
Arrow::ArrayDatum.new(build_int64_array([1, 2, 3])),
]
@options.start = Arrow::Int64Scalar.new(10)
cumulative_sum_function = Arrow::Function.find("cumulative_sum")
assert_equal(build_int64_array([11, 13, 16]),
cumulative_sum_function.execute(args, @options).value)
end
end

Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 203 additions & 0 deletions c_glib/arrow-glib/compute.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -254,6 +254,10 @@ G_BEGIN_DECLS
* #GArrowAssumeTimezoneOptions is a class to customize the `assume_timezone`
* function.
*
* #GArrowCumulativeOptions is a class to customize the cumulative functions
* such as `cumulative_sum`, `cumulative_prod`, `cumulative_max`, and
* `cumulative_min`.
*
* There are many functions to compute data on an array.
*/

Expand DownExpand Up@@ -6491,6 +6495,173 @@ garrow_assume_timezone_options_new(void)
return GARROW_ASSUME_TIMEZONE_OPTIONS(options);
}

typedef struct GArrowCumulativeOptionsPrivate_
{
GArrowScalar *start;
} GArrowCumulativeOptionsPrivate;

enum {
PROP_CUMULATIVE_OPTIONS_START = 1,
PROP_CUMULATIVE_OPTIONS_SKIP_NULLS,
};

G_DEFINE_TYPE_WITH_PRIVATE(GArrowCumulativeOptions,
garrow_cumulative_options,
GARROW_TYPE_FUNCTION_OPTIONS)

#define GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object) \
static_cast<GArrowCumulativeOptionsPrivate *>( \
garrow_cumulative_options_get_instance_private(GARROW_CUMULATIVE_OPTIONS(object)))

static void
garrow_cumulative_options_dispose(GObject *object)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);

if (priv->start) {
g_object_unref(priv->start);
priv->start = nullptr;
}

G_OBJECT_CLASS(garrow_cumulative_options_parent_class)->dispose(object);
}

static void
garrow_cumulative_options_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
auto options = garrow_cumulative_options_get_raw(GARROW_CUMULATIVE_OPTIONS(object));

switch (prop_id) {
case PROP_CUMULATIVE_OPTIONS_START:
{
auto scalar = GARROW_SCALAR(g_value_get_object(value));
if (priv->start == scalar) {
return;
}
if (priv->start) {
g_object_unref(priv->start);
}
priv->start = scalar;
if (priv->start) {
g_object_ref(priv->start);
options->start = garrow_scalar_get_raw(scalar);
} else {
options->start = std::nullopt;
}
break;
}
case PROP_CUMULATIVE_OPTIONS_SKIP_NULLS:
options->skip_nulls = g_value_get_boolean(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_cumulative_options_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
auto options = garrow_cumulative_options_get_raw(GARROW_CUMULATIVE_OPTIONS(object));

switch (prop_id) {
case PROP_CUMULATIVE_OPTIONS_START:
{
if (priv->start) {
g_value_set_object(value, G_OBJECT(priv->start));
} else {
g_value_set_object(value, NULL);
}
break;
}
case PROP_CUMULATIVE_OPTIONS_SKIP_NULLS:
g_value_set_boolean(value, options->skip_nulls);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_cumulative_options_init(GArrowCumulativeOptions *object)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
priv->start = nullptr;
auto function_options_priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
function_options_priv->options = static_cast<arrow::compute::FunctionOptions *>(
new arrow::compute::CumulativeOptions());
}

static void
garrow_cumulative_options_class_init(GArrowCumulativeOptionsClass *klass)
{
auto gobject_class = G_OBJECT_CLASS(klass);

gobject_class->dispose = garrow_cumulative_options_dispose;
gobject_class->set_property = garrow_cumulative_options_set_property;
gobject_class->get_property = garrow_cumulative_options_get_property;

arrow::compute::CumulativeOptions options;

GParamSpec *spec;
/**
* GArrowCumulativeOptions:start:
*
* Optional starting value for cumulative operation computation.
*
* Since: 23.0.0
*/
spec =
g_param_spec_object("start",
"Start",
"Optional starting value for cumulative operation computation",
GARROW_TYPE_SCALAR,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class, PROP_CUMULATIVE_OPTIONS_START, spec);

/**
* GArrowCumulativeOptions:skip-nulls:
*
* If true, nulls in the input are ignored and produce a corresponding null output.
* When false, the first null encountered is propagated through the remaining output.
*
* Since: 23.0.0
*/
spec = g_param_spec_boolean(
"skip-nulls",
"Skip nulls",
"If true, nulls in the input are ignored and produce a corresponding null output. "
"When false, the first null encountered is propagated through the remaining output",
options.skip_nulls,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
PROP_CUMULATIVE_OPTIONS_SKIP_NULLS,
spec);
}

/**
* garrow_cumulative_options_new:
*
* Returns: A newly created #GArrowCumulativeOptions.
*
* Since: 23.0.0
*/
GArrowCumulativeOptions *
garrow_cumulative_options_new(void)
{
auto options = g_object_new(GARROW_TYPE_CUMULATIVE_OPTIONS, NULL);
return GARROW_CUMULATIVE_OPTIONS(options);
}

G_END_DECLS

arrow::Result<arrow::FieldRef>
Expand DownExpand Up@@ -6627,6 +6798,11 @@ garrow_function_options_new_raw(const arrow::compute::FunctionOptions *arrow_opt
static_cast<const arrow::compute::AssumeTimezoneOptions *>(arrow_options);
auto options = garrow_assume_timezone_options_new_raw(arrow_assume_timezone_options);
return GARROW_FUNCTION_OPTIONS(options);
} else if (arrow_type_name == "CumulativeOptions") {
const auto arrow_cumulative_options =
static_cast<const arrow::compute::CumulativeOptions *>(arrow_options);
auto options = garrow_cumulative_options_new_raw(arrow_cumulative_options);
return GARROW_FUNCTION_OPTIONS(options);
} else {
auto options = g_object_new(GARROW_TYPE_FUNCTION_OPTIONS, NULL);
return GARROW_FUNCTION_OPTIONS(options);
Expand DownExpand Up@@ -7167,3 +7343,30 @@ garrow_assume_timezone_options_get_raw(GArrowAssumeTimezoneOptions *options)
return static_cast<arrow::compute::AssumeTimezoneOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}

GArrowCumulativeOptions *
garrow_cumulative_options_new_raw(const arrow::compute::CumulativeOptions *arrow_options)
{
GArrowScalar *start = nullptr;
if (arrow_options->start.has_value()) {
std::shared_ptr<arrow::Scalar> arrow_start = arrow_options->start.value();
start = garrow_scalar_new_raw(&arrow_start);
}
auto options = GARROW_CUMULATIVE_OPTIONS(g_object_new(GARROW_TYPE_CUMULATIVE_OPTIONS,
"start",
start,
"skip-nulls",
arrow_options->skip_nulls,
NULL));
if (start) {
g_object_unref(start);
}
return options;
}

arrow::compute::CumulativeOptions *
garrow_cumulative_options_get_raw(GArrowCumulativeOptions *options)
{
return static_cast<arrow::compute::CumulativeOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}
16 changes: 16 additions & 0 deletions c_glib/arrow-glib/compute.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -1173,4 +1173,20 @@ GARROW_AVAILABLE_IN_23_0
GArrowAssumeTimezoneOptions *
garrow_assume_timezone_options_new(void);

#define GARROW_TYPE_CUMULATIVE_OPTIONS (garrow_cumulative_options_get_type())
GARROW_AVAILABLE_IN_23_0
G_DECLARE_DERIVABLE_TYPE(GArrowCumulativeOptions,
garrow_cumulative_options,
GARROW,
CUMULATIVE_OPTIONS,
GArrowFunctionOptions)
struct _GArrowCumulativeOptionsClass
{
GArrowFunctionOptionsClass parent_class;
};

GARROW_AVAILABLE_IN_23_0
GArrowCumulativeOptions *
garrow_cumulative_options_new(void);

G_END_DECLS
5 changes: 5 additions & 0 deletions c_glib/arrow-glib/compute.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -181,3 +181,8 @@ garrow_assume_timezone_options_new_raw(
const arrow::compute::AssumeTimezoneOptions *arrow_options);
arrow::compute::AssumeTimezoneOptions *
garrow_assume_timezone_options_get_raw(GArrowAssumeTimezoneOptions *options);

GArrowCumulativeOptions *
garrow_cumulative_options_new_raw(const arrow::compute::CumulativeOptions *arrow_options);
arrow::compute::CumulativeOptions *
garrow_cumulative_options_get_raw(GArrowCumulativeOptions *options);
64 changes: 64 additions & 0 deletions c_glib/test/test-cumulative-options.rb
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
# 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.

class TestCumulativeOptions < Test::Unit::TestCase
include Helper::Buildable

def setup
@options = Arrow::CumulativeOptions.new
end

def test_start_property
assert_nil(@options.start)
start_scalar = Arrow::Int64Scalar.new(10)
@options.start = start_scalar
assert_equal(start_scalar, @options.start)
@options.start = nil
assert_nil(@options.start)
end

def test_skip_nulls_property
assert do
!@options.skip_nulls?
end
@options.skip_nulls = true
assert do
@options.skip_nulls?
end
end

def test_cumulative_sum_with_skip_nulls
args = [
Arrow::ArrayDatum.new(build_int64_array([1, 2, 3, nil, 4, 5])),
]
@options.skip_nulls = true
cumulative_sum_function = Arrow::Function.find("cumulative_sum")
assert_equal(build_int64_array([1, 3, 6, nil, 10, 15]),
cumulative_sum_function.execute(args, @options).value)
end

def test_cumulative_sum_with_start
args = [
Arrow::ArrayDatum.new(build_int64_array([1, 2, 3])),
]
@options.start = Arrow::Int64Scalar.new(10)
cumulative_sum_function = Arrow::Function.find("cumulative_sum")
assert_equal(build_int64_array([11, 13, 16]),
cumulative_sum_function.execute(args, @options).value)
end
end

Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length \u003e 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 203 additions & 0 deletions c_glib/arrow-glib/compute.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -254,6 +254,10 @@ G_BEGIN_DECLS
* #GArrowAssumeTimezoneOptions is a class to customize the `assume_timezone`
* function.
*
* #GArrowCumulativeOptions is a class to customize the cumulative functions
* such as `cumulative_sum`, `cumulative_prod`, `cumulative_max`, and
* `cumulative_min`.
*
* There are many functions to compute data on an array.
*/

Expand DownExpand Up@@ -6491,6 +6495,173 @@ garrow_assume_timezone_options_new(void)
return GARROW_ASSUME_TIMEZONE_OPTIONS(options);
}

typedef struct GArrowCumulativeOptionsPrivate_
{
GArrowScalar *start;
} GArrowCumulativeOptionsPrivate;

enum {
PROP_CUMULATIVE_OPTIONS_START = 1,
PROP_CUMULATIVE_OPTIONS_SKIP_NULLS,
};

G_DEFINE_TYPE_WITH_PRIVATE(GArrowCumulativeOptions,
garrow_cumulative_options,
GARROW_TYPE_FUNCTION_OPTIONS)

#define GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object) \
static_cast<GArrowCumulativeOptionsPrivate *>( \
garrow_cumulative_options_get_instance_private(GARROW_CUMULATIVE_OPTIONS(object)))

static void
garrow_cumulative_options_dispose(GObject *object)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);

if (priv->start) {
g_object_unref(priv->start);
priv->start = nullptr;
}

G_OBJECT_CLASS(garrow_cumulative_options_parent_class)->dispose(object);
}

static void
garrow_cumulative_options_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
auto options = garrow_cumulative_options_get_raw(GARROW_CUMULATIVE_OPTIONS(object));

switch (prop_id) {
case PROP_CUMULATIVE_OPTIONS_START:
{
auto scalar = GARROW_SCALAR(g_value_get_object(value));
if (priv->start == scalar) {
return;
}
if (priv->start) {
g_object_unref(priv->start);
}
priv->start = scalar;
if (priv->start) {
g_object_ref(priv->start);
options->start = garrow_scalar_get_raw(scalar);
} else {
options->start = std::nullopt;
}
break;
}
case PROP_CUMULATIVE_OPTIONS_SKIP_NULLS:
options->skip_nulls = g_value_get_boolean(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_cumulative_options_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
auto options = garrow_cumulative_options_get_raw(GARROW_CUMULATIVE_OPTIONS(object));

switch (prop_id) {
case PROP_CUMULATIVE_OPTIONS_START:
{
if (priv->start) {
g_value_set_object(value, G_OBJECT(priv->start));
} else {
g_value_set_object(value, NULL);
}
break;
}
case PROP_CUMULATIVE_OPTIONS_SKIP_NULLS:
g_value_set_boolean(value, options->skip_nulls);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_cumulative_options_init(GArrowCumulativeOptions *object)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
priv->start = nullptr;
auto function_options_priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
function_options_priv->options = static_cast<arrow::compute::FunctionOptions *>(
new arrow::compute::CumulativeOptions());
}

static void
garrow_cumulative_options_class_init(GArrowCumulativeOptionsClass *klass)
{
auto gobject_class = G_OBJECT_CLASS(klass);

gobject_class->dispose = garrow_cumulative_options_dispose;
gobject_class->set_property = garrow_cumulative_options_set_property;
gobject_class->get_property = garrow_cumulative_options_get_property;

arrow::compute::CumulativeOptions options;

GParamSpec *spec;
/**
* GArrowCumulativeOptions:start:
*
* Optional starting value for cumulative operation computation.
*
* Since: 23.0.0
*/
spec =
g_param_spec_object("start",
"Start",
"Optional starting value for cumulative operation computation",
GARROW_TYPE_SCALAR,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class, PROP_CUMULATIVE_OPTIONS_START, spec);

/**
* GArrowCumulativeOptions:skip-nulls:
*
* If true, nulls in the input are ignored and produce a corresponding null output.
* When false, the first null encountered is propagated through the remaining output.
*
* Since: 23.0.0
*/
spec = g_param_spec_boolean(
"skip-nulls",
"Skip nulls",
"If true, nulls in the input are ignored and produce a corresponding null output. "
"When false, the first null encountered is propagated through the remaining output",
options.skip_nulls,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
PROP_CUMULATIVE_OPTIONS_SKIP_NULLS,
spec);
}

/**
* garrow_cumulative_options_new:
*
* Returns: A newly created #GArrowCumulativeOptions.
*
* Since: 23.0.0
*/
GArrowCumulativeOptions *
garrow_cumulative_options_new(void)
{
auto options = g_object_new(GARROW_TYPE_CUMULATIVE_OPTIONS, NULL);
return GARROW_CUMULATIVE_OPTIONS(options);
}

G_END_DECLS

arrow::Result<arrow::FieldRef>
Expand DownExpand Up@@ -6627,6 +6798,11 @@ garrow_function_options_new_raw(const arrow::compute::FunctionOptions *arrow_opt
static_cast<const arrow::compute::AssumeTimezoneOptions *>(arrow_options);
auto options = garrow_assume_timezone_options_new_raw(arrow_assume_timezone_options);
return GARROW_FUNCTION_OPTIONS(options);
} else if (arrow_type_name == "CumulativeOptions") {
const auto arrow_cumulative_options =
static_cast<const arrow::compute::CumulativeOptions *>(arrow_options);
auto options = garrow_cumulative_options_new_raw(arrow_cumulative_options);
return GARROW_FUNCTION_OPTIONS(options);
} else {
auto options = g_object_new(GARROW_TYPE_FUNCTION_OPTIONS, NULL);
return GARROW_FUNCTION_OPTIONS(options);
Expand DownExpand Up@@ -7167,3 +7343,30 @@ garrow_assume_timezone_options_get_raw(GArrowAssumeTimezoneOptions *options)
return static_cast<arrow::compute::AssumeTimezoneOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}

GArrowCumulativeOptions *
garrow_cumulative_options_new_raw(const arrow::compute::CumulativeOptions *arrow_options)
{
GArrowScalar *start = nullptr;
if (arrow_options->start.has_value()) {
std::shared_ptr<arrow::Scalar> arrow_start = arrow_options->start.value();
start = garrow_scalar_new_raw(&arrow_start);
}
auto options = GARROW_CUMULATIVE_OPTIONS(g_object_new(GARROW_TYPE_CUMULATIVE_OPTIONS,
"start",
start,
"skip-nulls",
arrow_options->skip_nulls,
NULL));
if (start) {
g_object_unref(start);
}
return options;
}

arrow::compute::CumulativeOptions *
garrow_cumulative_options_get_raw(GArrowCumulativeOptions *options)
{
return static_cast<arrow::compute::CumulativeOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}
16 changes: 16 additions & 0 deletions c_glib/arrow-glib/compute.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -1173,4 +1173,20 @@ GARROW_AVAILABLE_IN_23_0
GArrowAssumeTimezoneOptions *
garrow_assume_timezone_options_new(void);

#define GARROW_TYPE_CUMULATIVE_OPTIONS (garrow_cumulative_options_get_type())
GARROW_AVAILABLE_IN_23_0
G_DECLARE_DERIVABLE_TYPE(GArrowCumulativeOptions,
garrow_cumulative_options,
GARROW,
CUMULATIVE_OPTIONS,
GArrowFunctionOptions)
struct _GArrowCumulativeOptionsClass
{
GArrowFunctionOptionsClass parent_class;
};

GARROW_AVAILABLE_IN_23_0
GArrowCumulativeOptions *
garrow_cumulative_options_new(void);

G_END_DECLS
5 changes: 5 additions & 0 deletions c_glib/arrow-glib/compute.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -181,3 +181,8 @@ garrow_assume_timezone_options_new_raw(
const arrow::compute::AssumeTimezoneOptions *arrow_options);
arrow::compute::AssumeTimezoneOptions *
garrow_assume_timezone_options_get_raw(GArrowAssumeTimezoneOptions *options);

GArrowCumulativeOptions *
garrow_cumulative_options_new_raw(const arrow::compute::CumulativeOptions *arrow_options);
arrow::compute::CumulativeOptions *
garrow_cumulative_options_get_raw(GArrowCumulativeOptions *options);
64 changes: 64 additions & 0 deletions c_glib/test/test-cumulative-options.rb
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
# 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.

class TestCumulativeOptions < Test::Unit::TestCase
include Helper::Buildable

def setup
@options = Arrow::CumulativeOptions.new
end

def test_start_property
assert_nil(@options.start)
start_scalar = Arrow::Int64Scalar.new(10)
@options.start = start_scalar
assert_equal(start_scalar, @options.start)
@options.start = nil
assert_nil(@options.start)
end

def test_skip_nulls_property
assert do
!@options.skip_nulls?
end
@options.skip_nulls = true
assert do
@options.skip_nulls?
end
end

def test_cumulative_sum_with_skip_nulls
args = [
Arrow::ArrayDatum.new(build_int64_array([1, 2, 3, nil, 4, 5])),
]
@options.skip_nulls = true
cumulative_sum_function = Arrow::Function.find("cumulative_sum")
assert_equal(build_int64_array([1, 3, 6, nil, 10, 15]),
cumulative_sum_function.execute(args, @options).value)
end

def test_cumulative_sum_with_start
args = [
Arrow::ArrayDatum.new(build_int64_array([1, 2, 3])),
]
@options.start = Arrow::Int64Scalar.new(10)
cumulative_sum_function = Arrow::Function.find("cumulative_sum")
assert_equal(build_int64_array([11, 13, 16]),
cumulative_sum_function.execute(args, @options).value)
end
end

Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 203 additions & 0 deletions c_glib/arrow-glib/compute.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -254,6 +254,10 @@ G_BEGIN_DECLS
* #GArrowAssumeTimezoneOptions is a class to customize the `assume_timezone`
* function.
*
* #GArrowCumulativeOptions is a class to customize the cumulative functions
* such as `cumulative_sum`, `cumulative_prod`, `cumulative_max`, and
* `cumulative_min`.
*
* There are many functions to compute data on an array.
*/

Expand DownExpand Up@@ -6491,6 +6495,173 @@ garrow_assume_timezone_options_new(void)
return GARROW_ASSUME_TIMEZONE_OPTIONS(options);
}

typedef struct GArrowCumulativeOptionsPrivate_
{
GArrowScalar *start;
} GArrowCumulativeOptionsPrivate;

enum {
PROP_CUMULATIVE_OPTIONS_START = 1,
PROP_CUMULATIVE_OPTIONS_SKIP_NULLS,
};

G_DEFINE_TYPE_WITH_PRIVATE(GArrowCumulativeOptions,
garrow_cumulative_options,
GARROW_TYPE_FUNCTION_OPTIONS)

#define GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object) \
static_cast<GArrowCumulativeOptionsPrivate *>( \
garrow_cumulative_options_get_instance_private(GARROW_CUMULATIVE_OPTIONS(object)))

static void
garrow_cumulative_options_dispose(GObject *object)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);

if (priv->start) {
g_object_unref(priv->start);
priv->start = nullptr;
}

G_OBJECT_CLASS(garrow_cumulative_options_parent_class)->dispose(object);
}

static void
garrow_cumulative_options_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
auto options = garrow_cumulative_options_get_raw(GARROW_CUMULATIVE_OPTIONS(object));

switch (prop_id) {
case PROP_CUMULATIVE_OPTIONS_START:
{
auto scalar = GARROW_SCALAR(g_value_get_object(value));
if (priv->start == scalar) {
return;
}
if (priv->start) {
g_object_unref(priv->start);
}
priv->start = scalar;
if (priv->start) {
g_object_ref(priv->start);
options->start = garrow_scalar_get_raw(scalar);
} else {
options->start = std::nullopt;
}
break;
}
case PROP_CUMULATIVE_OPTIONS_SKIP_NULLS:
options->skip_nulls = g_value_get_boolean(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_cumulative_options_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
auto options = garrow_cumulative_options_get_raw(GARROW_CUMULATIVE_OPTIONS(object));

switch (prop_id) {
case PROP_CUMULATIVE_OPTIONS_START:
{
if (priv->start) {
g_value_set_object(value, G_OBJECT(priv->start));
} else {
g_value_set_object(value, NULL);
}
break;
}
case PROP_CUMULATIVE_OPTIONS_SKIP_NULLS:
g_value_set_boolean(value, options->skip_nulls);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_cumulative_options_init(GArrowCumulativeOptions *object)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
priv->start = nullptr;
auto function_options_priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
function_options_priv->options = static_cast<arrow::compute::FunctionOptions *>(
new arrow::compute::CumulativeOptions());
}

static void
garrow_cumulative_options_class_init(GArrowCumulativeOptionsClass *klass)
{
auto gobject_class = G_OBJECT_CLASS(klass);

gobject_class->dispose = garrow_cumulative_options_dispose;
gobject_class->set_property = garrow_cumulative_options_set_property;
gobject_class->get_property = garrow_cumulative_options_get_property;

arrow::compute::CumulativeOptions options;

GParamSpec *spec;
/**
* GArrowCumulativeOptions:start:
*
* Optional starting value for cumulative operation computation.
*
* Since: 23.0.0
*/
spec =
g_param_spec_object("start",
"Start",
"Optional starting value for cumulative operation computation",
GARROW_TYPE_SCALAR,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class, PROP_CUMULATIVE_OPTIONS_START, spec);

/**
* GArrowCumulativeOptions:skip-nulls:
*
* If true, nulls in the input are ignored and produce a corresponding null output.
* When false, the first null encountered is propagated through the remaining output.
*
* Since: 23.0.0
*/
spec = g_param_spec_boolean(
"skip-nulls",
"Skip nulls",
"If true, nulls in the input are ignored and produce a corresponding null output. "
"When false, the first null encountered is propagated through the remaining output",
options.skip_nulls,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
PROP_CUMULATIVE_OPTIONS_SKIP_NULLS,
spec);
}

/**
* garrow_cumulative_options_new:
*
* Returns: A newly created #GArrowCumulativeOptions.
*
* Since: 23.0.0
*/
GArrowCumulativeOptions *
garrow_cumulative_options_new(void)
{
auto options = g_object_new(GARROW_TYPE_CUMULATIVE_OPTIONS, NULL);
return GARROW_CUMULATIVE_OPTIONS(options);
}

G_END_DECLS

arrow::Result<arrow::FieldRef>
Expand DownExpand Up@@ -6627,6 +6798,11 @@ garrow_function_options_new_raw(const arrow::compute::FunctionOptions *arrow_opt
static_cast<const arrow::compute::AssumeTimezoneOptions *>(arrow_options);
auto options = garrow_assume_timezone_options_new_raw(arrow_assume_timezone_options);
return GARROW_FUNCTION_OPTIONS(options);
} else if (arrow_type_name == "CumulativeOptions") {
const auto arrow_cumulative_options =
static_cast<const arrow::compute::CumulativeOptions *>(arrow_options);
auto options = garrow_cumulative_options_new_raw(arrow_cumulative_options);
return GARROW_FUNCTION_OPTIONS(options);
} else {
auto options = g_object_new(GARROW_TYPE_FUNCTION_OPTIONS, NULL);
return GARROW_FUNCTION_OPTIONS(options);
Expand DownExpand Up@@ -7167,3 +7343,30 @@ garrow_assume_timezone_options_get_raw(GArrowAssumeTimezoneOptions *options)
return static_cast<arrow::compute::AssumeTimezoneOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}

GArrowCumulativeOptions *
garrow_cumulative_options_new_raw(const arrow::compute::CumulativeOptions *arrow_options)
{
GArrowScalar *start = nullptr;
if (arrow_options->start.has_value()) {
std::shared_ptr<arrow::Scalar> arrow_start = arrow_options->start.value();
start = garrow_scalar_new_raw(&arrow_start);
}
auto options = GARROW_CUMULATIVE_OPTIONS(g_object_new(GARROW_TYPE_CUMULATIVE_OPTIONS,
"start",
start,
"skip-nulls",
arrow_options->skip_nulls,
NULL));
if (start) {
g_object_unref(start);
}
return options;
}

arrow::compute::CumulativeOptions *
garrow_cumulative_options_get_raw(GArrowCumulativeOptions *options)
{
return static_cast<arrow::compute::CumulativeOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}
16 changes: 16 additions & 0 deletions c_glib/arrow-glib/compute.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -1173,4 +1173,20 @@ GARROW_AVAILABLE_IN_23_0
GArrowAssumeTimezoneOptions *
garrow_assume_timezone_options_new(void);

#define GARROW_TYPE_CUMULATIVE_OPTIONS (garrow_cumulative_options_get_type())
GARROW_AVAILABLE_IN_23_0
G_DECLARE_DERIVABLE_TYPE(GArrowCumulativeOptions,
garrow_cumulative_options,
GARROW,
CUMULATIVE_OPTIONS,
GArrowFunctionOptions)
struct _GArrowCumulativeOptionsClass
{
GArrowFunctionOptionsClass parent_class;
};

GARROW_AVAILABLE_IN_23_0
GArrowCumulativeOptions *
garrow_cumulative_options_new(void);

G_END_DECLS
5 changes: 5 additions & 0 deletions c_glib/arrow-glib/compute.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -181,3 +181,8 @@ garrow_assume_timezone_options_new_raw(
const arrow::compute::AssumeTimezoneOptions *arrow_options);
arrow::compute::AssumeTimezoneOptions *
garrow_assume_timezone_options_get_raw(GArrowAssumeTimezoneOptions *options);

GArrowCumulativeOptions *
garrow_cumulative_options_new_raw(const arrow::compute::CumulativeOptions *arrow_options);
arrow::compute::CumulativeOptions *
garrow_cumulative_options_get_raw(GArrowCumulativeOptions *options);
64 changes: 64 additions & 0 deletions c_glib/test/test-cumulative-options.rb
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
# 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.

class TestCumulativeOptions < Test::Unit::TestCase
include Helper::Buildable

def setup
@options = Arrow::CumulativeOptions.new
end

def test_start_property
assert_nil(@options.start)
start_scalar = Arrow::Int64Scalar.new(10)
@options.start = start_scalar
assert_equal(start_scalar, @options.start)
@options.start = nil
assert_nil(@options.start)
end

def test_skip_nulls_property
assert do
!@options.skip_nulls?
end
@options.skip_nulls = true
assert do
@options.skip_nulls?
end
end

def test_cumulative_sum_with_skip_nulls
args = [
Arrow::ArrayDatum.new(build_int64_array([1, 2, 3, nil, 4, 5])),
]
@options.skip_nulls = true
cumulative_sum_function = Arrow::Function.find("cumulative_sum")
assert_equal(build_int64_array([1, 3, 6, nil, 10, 15]),
cumulative_sum_function.execute(args, @options).value)
end

def test_cumulative_sum_with_start
args = [
Arrow::ArrayDatum.new(build_int64_array([1, 2, 3])),
]
@options.start = Arrow::Int64Scalar.new(10)
cumulative_sum_function = Arrow::Function.find("cumulative_sum")
assert_equal(build_int64_array([11, 13, 16]),
cumulative_sum_function.execute(args, @options).value)
end
end

Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 203 additions & 0 deletions c_glib/arrow-glib/compute.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -254,6 +254,10 @@ G_BEGIN_DECLS
* #GArrowAssumeTimezoneOptions is a class to customize the `assume_timezone`
* function.
*
* #GArrowCumulativeOptions is a class to customize the cumulative functions
* such as `cumulative_sum`, `cumulative_prod`, `cumulative_max`, and
* `cumulative_min`.
*
* There are many functions to compute data on an array.
*/

Expand DownExpand Up@@ -6491,6 +6495,173 @@ garrow_assume_timezone_options_new(void)
return GARROW_ASSUME_TIMEZONE_OPTIONS(options);
}

typedef struct GArrowCumulativeOptionsPrivate_
{
GArrowScalar *start;
} GArrowCumulativeOptionsPrivate;

enum {
PROP_CUMULATIVE_OPTIONS_START = 1,
PROP_CUMULATIVE_OPTIONS_SKIP_NULLS,
};

G_DEFINE_TYPE_WITH_PRIVATE(GArrowCumulativeOptions,
garrow_cumulative_options,
GARROW_TYPE_FUNCTION_OPTIONS)

#define GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object) \
static_cast<GArrowCumulativeOptionsPrivate *>( \
garrow_cumulative_options_get_instance_private(GARROW_CUMULATIVE_OPTIONS(object)))

static void
garrow_cumulative_options_dispose(GObject *object)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);

if (priv->start) {
g_object_unref(priv->start);
priv->start = nullptr;
}

G_OBJECT_CLASS(garrow_cumulative_options_parent_class)->dispose(object);
}

static void
garrow_cumulative_options_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
auto options = garrow_cumulative_options_get_raw(GARROW_CUMULATIVE_OPTIONS(object));

switch (prop_id) {
case PROP_CUMULATIVE_OPTIONS_START:
{
auto scalar = GARROW_SCALAR(g_value_get_object(value));
if (priv->start == scalar) {
return;
}
if (priv->start) {
g_object_unref(priv->start);
}
priv->start = scalar;
if (priv->start) {
g_object_ref(priv->start);
options->start = garrow_scalar_get_raw(scalar);
} else {
options->start = std::nullopt;
}
break;
}
case PROP_CUMULATIVE_OPTIONS_SKIP_NULLS:
options->skip_nulls = g_value_get_boolean(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_cumulative_options_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
auto options = garrow_cumulative_options_get_raw(GARROW_CUMULATIVE_OPTIONS(object));

switch (prop_id) {
case PROP_CUMULATIVE_OPTIONS_START:
{
if (priv->start) {
g_value_set_object(value, G_OBJECT(priv->start));
} else {
g_value_set_object(value, NULL);
}
break;
}
case PROP_CUMULATIVE_OPTIONS_SKIP_NULLS:
g_value_set_boolean(value, options->skip_nulls);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_cumulative_options_init(GArrowCumulativeOptions *object)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
priv->start = nullptr;
auto function_options_priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
function_options_priv->options = static_cast<arrow::compute::FunctionOptions *>(
new arrow::compute::CumulativeOptions());
}

static void
garrow_cumulative_options_class_init(GArrowCumulativeOptionsClass *klass)
{
auto gobject_class = G_OBJECT_CLASS(klass);

gobject_class->dispose = garrow_cumulative_options_dispose;
gobject_class->set_property = garrow_cumulative_options_set_property;
gobject_class->get_property = garrow_cumulative_options_get_property;

arrow::compute::CumulativeOptions options;

GParamSpec *spec;
/**
* GArrowCumulativeOptions:start:
*
* Optional starting value for cumulative operation computation.
*
* Since: 23.0.0
*/
spec =
g_param_spec_object("start",
"Start",
"Optional starting value for cumulative operation computation",
GARROW_TYPE_SCALAR,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class, PROP_CUMULATIVE_OPTIONS_START, spec);

/**
* GArrowCumulativeOptions:skip-nulls:
*
* If true, nulls in the input are ignored and produce a corresponding null output.
* When false, the first null encountered is propagated through the remaining output.
*
* Since: 23.0.0
*/
spec = g_param_spec_boolean(
"skip-nulls",
"Skip nulls",
"If true, nulls in the input are ignored and produce a corresponding null output. "
"When false, the first null encountered is propagated through the remaining output",
options.skip_nulls,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
PROP_CUMULATIVE_OPTIONS_SKIP_NULLS,
spec);
}

/**
* garrow_cumulative_options_new:
*
* Returns: A newly created #GArrowCumulativeOptions.
*
* Since: 23.0.0
*/
GArrowCumulativeOptions *
garrow_cumulative_options_new(void)
{
auto options = g_object_new(GARROW_TYPE_CUMULATIVE_OPTIONS, NULL);
return GARROW_CUMULATIVE_OPTIONS(options);
}

G_END_DECLS

arrow::Result<arrow::FieldRef>
Expand DownExpand Up@@ -6627,6 +6798,11 @@ garrow_function_options_new_raw(const arrow::compute::FunctionOptions *arrow_opt
static_cast<const arrow::compute::AssumeTimezoneOptions *>(arrow_options);
auto options = garrow_assume_timezone_options_new_raw(arrow_assume_timezone_options);
return GARROW_FUNCTION_OPTIONS(options);
} else if (arrow_type_name == "CumulativeOptions") {
const auto arrow_cumulative_options =
static_cast<const arrow::compute::CumulativeOptions *>(arrow_options);
auto options = garrow_cumulative_options_new_raw(arrow_cumulative_options);
return GARROW_FUNCTION_OPTIONS(options);
} else {
auto options = g_object_new(GARROW_TYPE_FUNCTION_OPTIONS, NULL);
return GARROW_FUNCTION_OPTIONS(options);
Expand DownExpand Up@@ -7167,3 +7343,30 @@ garrow_assume_timezone_options_get_raw(GArrowAssumeTimezoneOptions *options)
return static_cast<arrow::compute::AssumeTimezoneOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}

GArrowCumulativeOptions *
garrow_cumulative_options_new_raw(const arrow::compute::CumulativeOptions *arrow_options)
{
GArrowScalar *start = nullptr;
if (arrow_options->start.has_value()) {
std::shared_ptr<arrow::Scalar> arrow_start = arrow_options->start.value();
start = garrow_scalar_new_raw(&arrow_start);
}
auto options = GARROW_CUMULATIVE_OPTIONS(g_object_new(GARROW_TYPE_CUMULATIVE_OPTIONS,
"start",
start,
"skip-nulls",
arrow_options->skip_nulls,
NULL));
if (start) {
g_object_unref(start);
}
return options;
}

arrow::compute::CumulativeOptions *
garrow_cumulative_options_get_raw(GArrowCumulativeOptions *options)
{
return static_cast<arrow::compute::CumulativeOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}
16 changes: 16 additions & 0 deletions c_glib/arrow-glib/compute.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -1173,4 +1173,20 @@ GARROW_AVAILABLE_IN_23_0
GArrowAssumeTimezoneOptions *
garrow_assume_timezone_options_new(void);

#define GARROW_TYPE_CUMULATIVE_OPTIONS (garrow_cumulative_options_get_type())
GARROW_AVAILABLE_IN_23_0
G_DECLARE_DERIVABLE_TYPE(GArrowCumulativeOptions,
garrow_cumulative_options,
GARROW,
CUMULATIVE_OPTIONS,
GArrowFunctionOptions)
struct _GArrowCumulativeOptionsClass
{
GArrowFunctionOptionsClass parent_class;
};

GARROW_AVAILABLE_IN_23_0
GArrowCumulativeOptions *
garrow_cumulative_options_new(void);

G_END_DECLS
5 changes: 5 additions & 0 deletions c_glib/arrow-glib/compute.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -181,3 +181,8 @@ garrow_assume_timezone_options_new_raw(
const arrow::compute::AssumeTimezoneOptions *arrow_options);
arrow::compute::AssumeTimezoneOptions *
garrow_assume_timezone_options_get_raw(GArrowAssumeTimezoneOptions *options);

GArrowCumulativeOptions *
garrow_cumulative_options_new_raw(const arrow::compute::CumulativeOptions *arrow_options);
arrow::compute::CumulativeOptions *
garrow_cumulative_options_get_raw(GArrowCumulativeOptions *options);
64 changes: 64 additions & 0 deletions c_glib/test/test-cumulative-options.rb
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
# 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.

class TestCumulativeOptions < Test::Unit::TestCase
include Helper::Buildable

def setup
@options = Arrow::CumulativeOptions.new
end

def test_start_property
assert_nil(@options.start)
start_scalar = Arrow::Int64Scalar.new(10)
@options.start = start_scalar
assert_equal(start_scalar, @options.start)
@options.start = nil
assert_nil(@options.start)
end

def test_skip_nulls_property
assert do
!@options.skip_nulls?
end
@options.skip_nulls = true
assert do
@options.skip_nulls?
end
end

def test_cumulative_sum_with_skip_nulls
args = [
Arrow::ArrayDatum.new(build_int64_array([1, 2, 3, nil, 4, 5])),
]
@options.skip_nulls = true
cumulative_sum_function = Arrow::Function.find("cumulative_sum")
assert_equal(build_int64_array([1, 3, 6, nil, 10, 15]),
cumulative_sum_function.execute(args, @options).value)
end

def test_cumulative_sum_with_start
args = [
Arrow::ArrayDatum.new(build_int64_array([1, 2, 3])),
]
@options.start = Arrow::Int64Scalar.new(10)
cumulative_sum_function = Arrow::Function.find("cumulative_sum")
assert_equal(build_int64_array([11, 13, 16]),
cumulative_sum_function.execute(args, @options).value)
end
end

Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 203 additions & 0 deletions c_glib/arrow-glib/compute.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -254,6 +254,10 @@ G_BEGIN_DECLS
* #GArrowAssumeTimezoneOptions is a class to customize the `assume_timezone`
* function.
*
* #GArrowCumulativeOptions is a class to customize the cumulative functions
* such as `cumulative_sum`, `cumulative_prod`, `cumulative_max`, and
* `cumulative_min`.
*
* There are many functions to compute data on an array.
*/

Expand DownExpand Up@@ -6491,6 +6495,173 @@ garrow_assume_timezone_options_new(void)
return GARROW_ASSUME_TIMEZONE_OPTIONS(options);
}

typedef struct GArrowCumulativeOptionsPrivate_
{
GArrowScalar *start;
} GArrowCumulativeOptionsPrivate;

enum {
PROP_CUMULATIVE_OPTIONS_START = 1,
PROP_CUMULATIVE_OPTIONS_SKIP_NULLS,
};

G_DEFINE_TYPE_WITH_PRIVATE(GArrowCumulativeOptions,
garrow_cumulative_options,
GARROW_TYPE_FUNCTION_OPTIONS)

#define GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object) \
static_cast<GArrowCumulativeOptionsPrivate *>( \
garrow_cumulative_options_get_instance_private(GARROW_CUMULATIVE_OPTIONS(object)))

static void
garrow_cumulative_options_dispose(GObject *object)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);

if (priv->start) {
g_object_unref(priv->start);
priv->start = nullptr;
}

G_OBJECT_CLASS(garrow_cumulative_options_parent_class)->dispose(object);
}

static void
garrow_cumulative_options_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
auto options = garrow_cumulative_options_get_raw(GARROW_CUMULATIVE_OPTIONS(object));

switch (prop_id) {
case PROP_CUMULATIVE_OPTIONS_START:
{
auto scalar = GARROW_SCALAR(g_value_get_object(value));
if (priv->start == scalar) {
return;
}
if (priv->start) {
g_object_unref(priv->start);
}
priv->start = scalar;
if (priv->start) {
g_object_ref(priv->start);
options->start = garrow_scalar_get_raw(scalar);
} else {
options->start = std::nullopt;
}
break;
}
case PROP_CUMULATIVE_OPTIONS_SKIP_NULLS:
options->skip_nulls = g_value_get_boolean(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_cumulative_options_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
auto options = garrow_cumulative_options_get_raw(GARROW_CUMULATIVE_OPTIONS(object));

switch (prop_id) {
case PROP_CUMULATIVE_OPTIONS_START:
{
if (priv->start) {
g_value_set_object(value, G_OBJECT(priv->start));
} else {
g_value_set_object(value, NULL);
}
break;
}
case PROP_CUMULATIVE_OPTIONS_SKIP_NULLS:
g_value_set_boolean(value, options->skip_nulls);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_cumulative_options_init(GArrowCumulativeOptions *object)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
priv->start = nullptr;
auto function_options_priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
function_options_priv->options = static_cast<arrow::compute::FunctionOptions *>(
new arrow::compute::CumulativeOptions());
}

static void
garrow_cumulative_options_class_init(GArrowCumulativeOptionsClass *klass)
{
auto gobject_class = G_OBJECT_CLASS(klass);

gobject_class->dispose = garrow_cumulative_options_dispose;
gobject_class->set_property = garrow_cumulative_options_set_property;
gobject_class->get_property = garrow_cumulative_options_get_property;

arrow::compute::CumulativeOptions options;

GParamSpec *spec;
/**
* GArrowCumulativeOptions:start:
*
* Optional starting value for cumulative operation computation.
*
* Since: 23.0.0
*/
spec =
g_param_spec_object("start",
"Start",
"Optional starting value for cumulative operation computation",
GARROW_TYPE_SCALAR,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class, PROP_CUMULATIVE_OPTIONS_START, spec);

/**
* GArrowCumulativeOptions:skip-nulls:
*
* If true, nulls in the input are ignored and produce a corresponding null output.
* When false, the first null encountered is propagated through the remaining output.
*
* Since: 23.0.0
*/
spec = g_param_spec_boolean(
"skip-nulls",
"Skip nulls",
"If true, nulls in the input are ignored and produce a corresponding null output. "
"When false, the first null encountered is propagated through the remaining output",
options.skip_nulls,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
PROP_CUMULATIVE_OPTIONS_SKIP_NULLS,
spec);
}

/**
* garrow_cumulative_options_new:
*
* Returns: A newly created #GArrowCumulativeOptions.
*
* Since: 23.0.0
*/
GArrowCumulativeOptions *
garrow_cumulative_options_new(void)
{
auto options = g_object_new(GARROW_TYPE_CUMULATIVE_OPTIONS, NULL);
return GARROW_CUMULATIVE_OPTIONS(options);
}

G_END_DECLS

arrow::Result<arrow::FieldRef>
Expand DownExpand Up@@ -6627,6 +6798,11 @@ garrow_function_options_new_raw(const arrow::compute::FunctionOptions *arrow_opt
static_cast<const arrow::compute::AssumeTimezoneOptions *>(arrow_options);
auto options = garrow_assume_timezone_options_new_raw(arrow_assume_timezone_options);
return GARROW_FUNCTION_OPTIONS(options);
} else if (arrow_type_name == "CumulativeOptions") {
const auto arrow_cumulative_options =
static_cast<const arrow::compute::CumulativeOptions *>(arrow_options);
auto options = garrow_cumulative_options_new_raw(arrow_cumulative_options);
return GARROW_FUNCTION_OPTIONS(options);
} else {
auto options = g_object_new(GARROW_TYPE_FUNCTION_OPTIONS, NULL);
return GARROW_FUNCTION_OPTIONS(options);
Expand DownExpand Up@@ -7167,3 +7343,30 @@ garrow_assume_timezone_options_get_raw(GArrowAssumeTimezoneOptions *options)
return static_cast<arrow::compute::AssumeTimezoneOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}

GArrowCumulativeOptions *
garrow_cumulative_options_new_raw(const arrow::compute::CumulativeOptions *arrow_options)
{
GArrowScalar *start = nullptr;
if (arrow_options->start.has_value()) {
std::shared_ptr<arrow::Scalar> arrow_start = arrow_options->start.value();
start = garrow_scalar_new_raw(&arrow_start);
}
auto options = GARROW_CUMULATIVE_OPTIONS(g_object_new(GARROW_TYPE_CUMULATIVE_OPTIONS,
"start",
start,
"skip-nulls",
arrow_options->skip_nulls,
NULL));
if (start) {
g_object_unref(start);
}
return options;
}

arrow::compute::CumulativeOptions *
garrow_cumulative_options_get_raw(GArrowCumulativeOptions *options)
{
return static_cast<arrow::compute::CumulativeOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}
16 changes: 16 additions & 0 deletions c_glib/arrow-glib/compute.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -1173,4 +1173,20 @@ GARROW_AVAILABLE_IN_23_0
GArrowAssumeTimezoneOptions *
garrow_assume_timezone_options_new(void);

#define GARROW_TYPE_CUMULATIVE_OPTIONS (garrow_cumulative_options_get_type())
GARROW_AVAILABLE_IN_23_0
G_DECLARE_DERIVABLE_TYPE(GArrowCumulativeOptions,
garrow_cumulative_options,
GARROW,
CUMULATIVE_OPTIONS,
GArrowFunctionOptions)
struct _GArrowCumulativeOptionsClass
{
GArrowFunctionOptionsClass parent_class;
};

GARROW_AVAILABLE_IN_23_0
GArrowCumulativeOptions *
garrow_cumulative_options_new(void);

G_END_DECLS
5 changes: 5 additions & 0 deletions c_glib/arrow-glib/compute.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -181,3 +181,8 @@ garrow_assume_timezone_options_new_raw(
const arrow::compute::AssumeTimezoneOptions *arrow_options);
arrow::compute::AssumeTimezoneOptions *
garrow_assume_timezone_options_get_raw(GArrowAssumeTimezoneOptions *options);

GArrowCumulativeOptions *
garrow_cumulative_options_new_raw(const arrow::compute::CumulativeOptions *arrow_options);
arrow::compute::CumulativeOptions *
garrow_cumulative_options_get_raw(GArrowCumulativeOptions *options);
64 changes: 64 additions & 0 deletions c_glib/test/test-cumulative-options.rb
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
# 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.

class TestCumulativeOptions < Test::Unit::TestCase
include Helper::Buildable

def setup
@options = Arrow::CumulativeOptions.new
end

def test_start_property
assert_nil(@options.start)
start_scalar = Arrow::Int64Scalar.new(10)
@options.start = start_scalar
assert_equal(start_scalar, @options.start)
@options.start = nil
assert_nil(@options.start)
end

def test_skip_nulls_property
assert do
!@options.skip_nulls?
end
@options.skip_nulls = true
assert do
@options.skip_nulls?
end
end

def test_cumulative_sum_with_skip_nulls
args = [
Arrow::ArrayDatum.new(build_int64_array([1, 2, 3, nil, 4, 5])),
]
@options.skip_nulls = true
cumulative_sum_function = Arrow::Function.find("cumulative_sum")
assert_equal(build_int64_array([1, 3, 6, nil, 10, 15]),
cumulative_sum_function.execute(args, @options).value)
end

def test_cumulative_sum_with_start
args = [
Arrow::ArrayDatum.new(build_int64_array([1, 2, 3])),
]
@options.start = Arrow::Int64Scalar.new(10)
cumulative_sum_function = Arrow::Function.find("cumulative_sum")
assert_equal(build_int64_array([11, 13, 16]),
cumulative_sum_function.execute(args, @options).value)
end
end

Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 203 additions & 0 deletions c_glib/arrow-glib/compute.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -254,6 +254,10 @@ G_BEGIN_DECLS
* #GArrowAssumeTimezoneOptions is a class to customize the `assume_timezone`
* function.
*
* #GArrowCumulativeOptions is a class to customize the cumulative functions
* such as `cumulative_sum`, `cumulative_prod`, `cumulative_max`, and
* `cumulative_min`.
*
* There are many functions to compute data on an array.
*/

Expand DownExpand Up@@ -6491,6 +6495,173 @@ garrow_assume_timezone_options_new(void)
return GARROW_ASSUME_TIMEZONE_OPTIONS(options);
}

typedef struct GArrowCumulativeOptionsPrivate_
{
GArrowScalar *start;
} GArrowCumulativeOptionsPrivate;

enum {
PROP_CUMULATIVE_OPTIONS_START = 1,
PROP_CUMULATIVE_OPTIONS_SKIP_NULLS,
};

G_DEFINE_TYPE_WITH_PRIVATE(GArrowCumulativeOptions,
garrow_cumulative_options,
GARROW_TYPE_FUNCTION_OPTIONS)

#define GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object) \
static_cast<GArrowCumulativeOptionsPrivate *>( \
garrow_cumulative_options_get_instance_private(GARROW_CUMULATIVE_OPTIONS(object)))

static void
garrow_cumulative_options_dispose(GObject *object)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);

if (priv->start) {
g_object_unref(priv->start);
priv->start = nullptr;
}

G_OBJECT_CLASS(garrow_cumulative_options_parent_class)->dispose(object);
}

static void
garrow_cumulative_options_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
auto options = garrow_cumulative_options_get_raw(GARROW_CUMULATIVE_OPTIONS(object));

switch (prop_id) {
case PROP_CUMULATIVE_OPTIONS_START:
{
auto scalar = GARROW_SCALAR(g_value_get_object(value));
if (priv->start == scalar) {
return;
}
if (priv->start) {
g_object_unref(priv->start);
}
priv->start = scalar;
if (priv->start) {
g_object_ref(priv->start);
options->start = garrow_scalar_get_raw(scalar);
} else {
options->start = std::nullopt;
}
break;
}
case PROP_CUMULATIVE_OPTIONS_SKIP_NULLS:
options->skip_nulls = g_value_get_boolean(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_cumulative_options_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
auto options = garrow_cumulative_options_get_raw(GARROW_CUMULATIVE_OPTIONS(object));

switch (prop_id) {
case PROP_CUMULATIVE_OPTIONS_START:
{
if (priv->start) {
g_value_set_object(value, G_OBJECT(priv->start));
} else {
g_value_set_object(value, NULL);
}
break;
}
case PROP_CUMULATIVE_OPTIONS_SKIP_NULLS:
g_value_set_boolean(value, options->skip_nulls);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}

static void
garrow_cumulative_options_init(GArrowCumulativeOptions *object)
{
auto priv = GARROW_CUMULATIVE_OPTIONS_GET_PRIVATE(object);
priv->start = nullptr;
auto function_options_priv = GARROW_FUNCTION_OPTIONS_GET_PRIVATE(object);
function_options_priv->options = static_cast<arrow::compute::FunctionOptions *>(
new arrow::compute::CumulativeOptions());
}

static void
garrow_cumulative_options_class_init(GArrowCumulativeOptionsClass *klass)
{
auto gobject_class = G_OBJECT_CLASS(klass);

gobject_class->dispose = garrow_cumulative_options_dispose;
gobject_class->set_property = garrow_cumulative_options_set_property;
gobject_class->get_property = garrow_cumulative_options_get_property;

arrow::compute::CumulativeOptions options;

GParamSpec *spec;
/**
* GArrowCumulativeOptions:start:
*
* Optional starting value for cumulative operation computation.
*
* Since: 23.0.0
*/
spec =
g_param_spec_object("start",
"Start",
"Optional starting value for cumulative operation computation",
GARROW_TYPE_SCALAR,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class, PROP_CUMULATIVE_OPTIONS_START, spec);

/**
* GArrowCumulativeOptions:skip-nulls:
*
* If true, nulls in the input are ignored and produce a corresponding null output.
* When false, the first null encountered is propagated through the remaining output.
*
* Since: 23.0.0
*/
spec = g_param_spec_boolean(
"skip-nulls",
"Skip nulls",
"If true, nulls in the input are ignored and produce a corresponding null output. "
"When false, the first null encountered is propagated through the remaining output",
options.skip_nulls,
static_cast<GParamFlags>(G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
PROP_CUMULATIVE_OPTIONS_SKIP_NULLS,
spec);
}

/**
* garrow_cumulative_options_new:
*
* Returns: A newly created #GArrowCumulativeOptions.
*
* Since: 23.0.0
*/
GArrowCumulativeOptions *
garrow_cumulative_options_new(void)
{
auto options = g_object_new(GARROW_TYPE_CUMULATIVE_OPTIONS, NULL);
return GARROW_CUMULATIVE_OPTIONS(options);
}

G_END_DECLS

arrow::Result<arrow::FieldRef>
Expand DownExpand Up@@ -6627,6 +6798,11 @@ garrow_function_options_new_raw(const arrow::compute::FunctionOptions *arrow_opt
static_cast<const arrow::compute::AssumeTimezoneOptions *>(arrow_options);
auto options = garrow_assume_timezone_options_new_raw(arrow_assume_timezone_options);
return GARROW_FUNCTION_OPTIONS(options);
} else if (arrow_type_name == "CumulativeOptions") {
const auto arrow_cumulative_options =
static_cast<const arrow::compute::CumulativeOptions *>(arrow_options);
auto options = garrow_cumulative_options_new_raw(arrow_cumulative_options);
return GARROW_FUNCTION_OPTIONS(options);
} else {
auto options = g_object_new(GARROW_TYPE_FUNCTION_OPTIONS, NULL);
return GARROW_FUNCTION_OPTIONS(options);
Expand DownExpand Up@@ -7167,3 +7343,30 @@ garrow_assume_timezone_options_get_raw(GArrowAssumeTimezoneOptions *options)
return static_cast<arrow::compute::AssumeTimezoneOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}

GArrowCumulativeOptions *
garrow_cumulative_options_new_raw(const arrow::compute::CumulativeOptions *arrow_options)
{
GArrowScalar *start = nullptr;
if (arrow_options->start.has_value()) {
std::shared_ptr<arrow::Scalar> arrow_start = arrow_options->start.value();
start = garrow_scalar_new_raw(&arrow_start);
}
auto options = GARROW_CUMULATIVE_OPTIONS(g_object_new(GARROW_TYPE_CUMULATIVE_OPTIONS,
"start",
start,
"skip-nulls",
arrow_options->skip_nulls,
NULL));
if (start) {
g_object_unref(start);
}
return options;
}

arrow::compute::CumulativeOptions *
garrow_cumulative_options_get_raw(GArrowCumulativeOptions *options)
{
return static_cast<arrow::compute::CumulativeOptions *>(
garrow_function_options_get_raw(GARROW_FUNCTION_OPTIONS(options)));
}
16 changes: 16 additions & 0 deletions c_glib/arrow-glib/compute.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -1173,4 +1173,20 @@ GARROW_AVAILABLE_IN_23_0
GArrowAssumeTimezoneOptions *
garrow_assume_timezone_options_new(void);

#define GARROW_TYPE_CUMULATIVE_OPTIONS (garrow_cumulative_options_get_type())
GARROW_AVAILABLE_IN_23_0
G_DECLARE_DERIVABLE_TYPE(GArrowCumulativeOptions,
garrow_cumulative_options,
GARROW,
CUMULATIVE_OPTIONS,
GArrowFunctionOptions)
struct _GArrowCumulativeOptionsClass
{
GArrowFunctionOptionsClass parent_class;
};

GARROW_AVAILABLE_IN_23_0
GArrowCumulativeOptions *
garrow_cumulative_options_new(void);

G_END_DECLS
5 changes: 5 additions & 0 deletions c_glib/arrow-glib/compute.hpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -181,3 +181,8 @@ garrow_assume_timezone_options_new_raw(
const arrow::compute::AssumeTimezoneOptions *arrow_options);
arrow::compute::AssumeTimezoneOptions *
garrow_assume_timezone_options_get_raw(GArrowAssumeTimezoneOptions *options);

GArrowCumulativeOptions *
garrow_cumulative_options_new_raw(const arrow::compute::CumulativeOptions *arrow_options);
arrow::compute::CumulativeOptions *
garrow_cumulative_options_get_raw(GArrowCumulativeOptions *options);
64 changes: 64 additions & 0 deletions c_glib/test/test-cumulative-options.rb
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
# 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.

class TestCumulativeOptions < Test::Unit::TestCase
include Helper::Buildable

def setup
@options = Arrow::CumulativeOptions.new
end

def test_start_property
assert_nil(@options.start)
start_scalar = Arrow::Int64Scalar.new(10)
@options.start = start_scalar
assert_equal(start_scalar, @options.start)
@options.start = nil
assert_nil(@options.start)
end

def test_skip_nulls_property
assert do
!@options.skip_nulls?
end
@options.skip_nulls = true
assert do
@options.skip_nulls?
end
end

def test_cumulative_sum_with_skip_nulls
args = [
Arrow::ArrayDatum.new(build_int64_array([1, 2, 3, nil, 4, 5])),
]
@options.skip_nulls = true
cumulative_sum_function = Arrow::Function.find("cumulative_sum")
assert_equal(build_int64_array([1, 3, 6, nil, 10, 15]),
cumulative_sum_function.execute(args, @options).value)
end

def test_cumulative_sum_with_start
args = [
Arrow::ArrayDatum.new(build_int64_array([1, 2, 3])),
]
@options.start = Arrow::Int64Scalar.new(10)
cumulative_sum_function = Arrow::Function.find("cumulative_sum")
assert_equal(build_int64_array([11, 13, 16]),
cumulative_sum_function.execute(args, @options).value)
end
end

Loading