Skip to content

Inconsistent behavoir of update set map = / +=  #927

Closed

Description

@topofocus

ArcadeDB Version: 23.2.1

Add a key-value pair to an embedded map

Expected behavior

update #41:0 set bars.2023-03-08 = { "volume": 134 }
adds the map to the bars property

update #41:0 set bars += { "2023-03-08": { "volume": 134 }}
is equivalent

Actual behavior

the last query raises an error

Steps to reproduce

Create a vertex class contract
then: create property contract.bars MAP
insert a record. Assuming its rid is #341
update set bars = map( "23-03-24" , { "volume": 100 } }
then
update #41:0 set bars += { "2023-03-08": { "volume": 134 }}

raises an Error and nothing is updated

Activity

  1. topofocus commented on Mar 10, 2023

    @topofocus
    Author

    Upon further tests:

    The alternative syntax

    update set bars += [ "23-03-24" , { "volume": 100 } ]

    works

    10.03.(17:07:15) INFO->Q: INSERT INTO test_document CONTENT {"name":"Nesti","age":4} 
    10.03.(17:07:15) INFO->Q:  update #25:1 set d = MAP ( 'testkey', { 'nested_key': 'nested_value' } ) 
    10.03.(17:07:15) INFO->Q:  update #25:1 set d.testkey2 = { 'nested_key2': 'nested_value2'} 
    10.03.(17:07:15) INFO->Q:  update #25:1 set d += ['testkey3', { 'nested_key3': 'nested_value3'} ]
    
        Then { map_dataset.refresh.d == { testkey: { nested_key: 'nested_value' },
                                        testkey2: { nested_key2: 'nested_value2' },
                                        testkey3: { nested_key3: 'nested_value3' }  }}  passes
  2. lvca commented on Mar 10, 2023

    @lvca
    Member

    @topofocus so this is the only one that doesn't work, right?

    update XXX set bars += { "2023-03-08": { "volume": 134 }}

  3. self-assigned this
    on Mar 10, 2023
  4. added this to the 23.3.1 milestone on Mar 10, 2023
  5. topofocus commented on Mar 11, 2023

    @topofocus
    Author

    only
    update XXX set bars += [ "2023-03-08": { "volume": 134 } ]
    and the old form
    update XXX set bars.2023-03-08 = { "volume": 134 } ]

    work

  6. lvca commented on Mar 15, 2023

    @lvca
    Member

    I found this test case (that works) in our code base:

      @Test
      public void testPlusAssignMap() {
        ResultSet result = database.command("sql", "insert into " + className + " set map1 = {'name':'Jay'}, map2 = {'name':'Jay'}");
        final RID rid = result.next().getIdentity().get();
        result = database.command("sql", "update " + rid + " set map1 += { 'last': 'Miner'}, map2 += [ 'last', 'Miner']");
        Assertions.assertTrue(result.hasNext());
        Assertions.assertNotNull(result.next());
    
        result = database.command("sql", "select from " + rid);
        Assertions.assertTrue(result.hasNext());
        Result item = result.next();
        Assertions.assertNotNull(item);
    
        Map<String, String> map1 = item.getProperty("map1");
        Assertions.assertEquals(2, map1.size());
        Assertions.assertEquals("Jay", map1.get("name"));
        Assertions.assertEquals("Miner", map1.get("last"));
    
        Map<String, String> map2 = item.getProperty("map2");
        Assertions.assertEquals(2, map2.size());
        Assertions.assertEquals("Jay", map2.get("name"));
        Assertions.assertEquals("Miner", map2.get("last"));
      }

    So it could be related to the fact that a map has another map embedded. Checking it....

  7. lvca commented on Mar 15, 2023

    @lvca
    Member

    Just created this new test case base on your input and works with the latest version:

      @Test
      public void testPlusAssignNestedMaps() {
        ResultSet result = database.command("sql", "insert into " + className + " set map1 = {}");
        final RID rid = result.next().getIdentity().get();
    
        database.command("sql", "update " + rid + " set bars = map( \"23-03-24\" , { \"volume\": 100 } )");
    
        result = database.command("sql", "update " + rid + " set bars += { \"2023-03-08\": { \"volume\": 134 }}");
        Assertions.assertTrue(result.hasNext());
        Assertions.assertNotNull(result.next());
    
        result = database.command("sql", "select from " + rid);
        Assertions.assertTrue(result.hasNext());
        Result item = result.next();
        Assertions.assertNotNull(item);
    
        Map<String, Object> map1 = item.getProperty("bars");
        Assertions.assertEquals(2, map1.size());
    
        Map nestedMap = (Map) map1.get("23-03-24");
        Assertions.assertNotNull(nestedMap);
        Assertions.assertEquals(100, nestedMap.get("volume"));
    
        nestedMap = (Map) map1.get("2023-03-08");
        Assertions.assertNotNull(nestedMap);
        Assertions.assertEquals(134, nestedMap.get("volume"));
      }

    How this is different from yours?

  8. added a commit that references this issue on Mar 15, 2023
  9. topofocus commented on Mar 15, 2023

    @topofocus
    Author

    Just checked:

    5.03.(18:37:12) INFO->Q: update #31:0 set d += {'testkey3': { 'nested_key3': 'nested_value3'} }
    15.03.(18:37:12) INFO->Q: update #31:0 set d += ['testkey4', { 'nested_key4': 'nested_value4' }

    are producing identical results now.

    Did not change anything, but now my tests also pass ...

  10. lvca commented on Mar 15, 2023

    @lvca
    Member

    Which version did you test with? Still the 23.2.1 reported at the beginning of the issue or the most recent one?

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions