Created
January 2, 2016 06:35
-
-
Save mmacfadden/af1fb4ef0f596a7bcc70 to your computer and use it in GitHub Desktop.
Demonstrates an issue with inserting nested embedded maps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.orientechnologies.orient.core.sql; | |
import org.testng.annotations.Test; | |
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; | |
import com.orientechnologies.orient.core.metadata.schema.OType; | |
import com.orientechnologies.orient.core.record.impl.ODocument; | |
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; | |
import static org.testng.Assert.*; | |
public class SQLInsertEmbeddedMapTest { | |
@Test | |
public void testEmbeddedMapInsert() throws Exception { | |
final ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:SQLInsertEmbeddedMapTest"); | |
db.create(); | |
db.command(new OCommandSQL("CREATE class Test")).execute(); | |
OCommandSQL insertCommand = | |
new OCommandSQL("INSERT INTO Test SET map1 = { 'map2': { 'key': 'value' } }"); | |
OSQLSynchQuery<ODocument> selectQuery = | |
new OSQLSynchQuery<ODocument>("SELECT FROM Test"); | |
OSQLSynchQuery<ODocument> map1TypeQuery = | |
new OSQLSynchQuery<ODocument>("SELECT map1.type() as type FROM Test"); | |
OSQLSynchQuery<ODocument> map2TypeQuery = | |
new OSQLSynchQuery<ODocument>("SELECT map1.map2.type() as type FROM Test"); | |
db.command(insertCommand).execute(); | |
ODocument doc = (ODocument) db.query(selectQuery).get(0); | |
System.out.println(doc.toJSON()); | |
ODocument map1Type = (ODocument) db.query(map1TypeQuery).get(0); | |
assertEquals(map1Type.field("type"), OType.EMBEDDEDMAP.toString()); | |
ODocument map2Type = (ODocument) db.query(map2TypeQuery).get(0); | |
assertEquals(map2Type.field("type"), OType.EMBEDDEDMAP.toString()); | |
// Clear out the inserted data. | |
db.command(new OCommandSQL("DELETE FROM Test")).execute(); | |
// create a schema property for map1 as an EMBEDDEDMAP | |
db.command(new OCommandSQL("CREATE property Test.map1 EMBEDDEDMAP")).execute(); | |
db.command(insertCommand).execute(); | |
doc = (ODocument) db.query(selectQuery).get(0); | |
System.out.println(doc.toJSON()); | |
map1Type = (ODocument) db.query(map1TypeQuery).get(0); | |
assertEquals(map1Type.field("type"), OType.EMBEDDEDMAP.toString()); | |
// Currently Failing, now comes back as EMBEDDED | |
map2Type = (ODocument) db.query(map2TypeQuery).get(0); | |
assertEquals(map2Type.field("type"), OType.EMBEDDEDMAP.toString()); | |
db.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment