Skip to content

[HELP NEEDED] How to insert RAND(seed) in ORDER BY clause for impala backend? #11276

Open
@94929

Description

@94929

Problem

I need deterministic random sampling within partitions using a seed value. I want to generate SQL like ORDER BY RAND(42) but cannot find a way to pass a seed parameter to ibis random functions.

Current Code

# This works for random sampling (no seed)
order_by = [ibis.random()]
window_spec = ibis.window(group_by=['day_partition', 'hour_partition'], order_by=order_by)

Desired SQL Output

ROW_NUMBER() OVER (PARTITION BY day_partition, hour_partition ORDER BY RAND(42))

Attempted Solutions

  1. ibis.random() with seed - No seed parameter supported
  2. ops.RandomScalar(seed=42) - TypeError: got an unexpected keyword argument 'seed'
  3. ibis.sql(f"RAND({seed})") - AttributeError: module 'ibis' has no attribute 'sql'
  4. ibis.literal(f"RAND({seed})") - Produces string literal 'RAND(42)' instead of function call
  5. ibis.param("int64") - Results in ORDER BY 42 (constant value, no randomness)

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions