Skip to content

Question: Understanding the working of first() and last() functions #925

Closed

Description

@darpan-vyas

ArcadeDB Version: ArcadeDB Server v23.3.1-SNAPSHOT (build 143b1a6/1677646375828/main)

JDK Version: JMX Metrics

OS: MacOS Ventura 13.2.1

Expected behavior

Instead of returning null, the first and last values of the multi-valued field (dataset_name/dataset_name_l) created in the subquery should be returned upon using the first() and last() functions respectively.

PS: I'm still learning about ArcadeDB referring to the official documentation. It's possible that I misunderstood something.

Actual behavior

Query 1: select name,first(dataset_name) from (select name,in('in_use').name as dataset_name from job)
Query 2: select name,first(dataset_name_l) from (select name,dataset_name.convert('list') as dataset_name_l from (select name,in('in_use').name as dataset_name from job))

There are a total of 7 job-type nodes and 15 dataset-type nodes. A job is attached to three dataset-type nodes in total (2 with 'in_use' and 1 with 'has_created' type edge). Please refer to the attached image for better visualization (image 1).

I want to check the working of the first() and last() functions. Both queries were created with the same intent. The subquery select name,in('in_use').name as dataset_name from job returns the expected result (image 2), however, while using the said functions to extract the first and last values, the result (images 3 & 4) comes out to be null with both queries.

Image 1:
image

Image 2:
image

Image 3:
image

Image 4:
image

Steps to reproduce

  • There are two node types 'dataset' and 'job', with the string datatype property 'name' defined for both. The type 'dataset' contains 15 nodes, named from 'd1, d2,d3,...,d14', and type 'job' contains 7 nodes, named from 'j1,j2,...,j7'.
  • I connected the database in the console and queried it to check the working of the FIRST() and LAST() functions.

Activity

  1. self-assigned this
    on Mar 9, 2023
  2. added
    question
    on Mar 9, 2023
  3. added this to the 23.3.1 milestone on Mar 9, 2023
  4. lvca commented on Mar 9, 2023

    @lvca
    Member

    Thanks, @darpan-vyas for the very detailed description. Could you please try if these work?

    select name, first($dataset_name) as first
    let dataset_name = in('in_use').name
    from job

    Or this:

    select name, first($datasets).name as first
    let datasets = in('in_use')
    from job
  5. darpan-vyas commented on Mar 9, 2023

    @darpan-vyas
    Author

    Hey Luca, thanks for the quick response.

    I checked both queries in the console. It returned the below-mentioned error.

    image

  6. lvca commented on Mar 9, 2023

    @lvca
    Member

    Sorry, the LET goes after the from:

    Query 1:

    select name, first($dataset_name) as first
    from job
    let dataset_name = in('in_use').name

    Query 2

    select name, first($datasets).name as first
    from job
    let datasets = in('in_use')
  7. darpan-vyas commented on Mar 9, 2023

    @darpan-vyas
    Author

    Hey Luca, thanks a lot. This worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

question

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions