Skip to content

Select with or without * on vertexes has different behaviour #2378

@robfrank

Description

@robfrank

Given this test:

  @Test
  void testCreateHiddenProperty() {
    database.command("sql", "create vertex type testHiddenProperty").close();
    database.command("sql", "CREATE property testHiddenProperty.name STRING (hidden)").close();

    DocumentType clazz = database.getSchema().getType("testHiddenProperty");
    Property nameProperty = clazz.getProperty(PROP_NAME);

    assertThat(nameProperty.getName()).isEqualTo(PROP_NAME);
    assertThat(nameProperty.getType()).isEqualTo(Type.STRING);
    assertThat(nameProperty.isHidden()).isTrue();

    database.transaction(() -> {

      database.command("sql", "INSERT INTO testHiddenProperty SET name = 'hidden' , no_secret = 'seeme' ").close();
    });

    // check that the property is hidden when select *
    ResultSet result = database.query("sql", "SELECT * FROM testHiddenProperty");
    assertThat(result.hasNext()).isTrue();
    Result doc = result.next();
    assertThat(doc.getPropertyNames()).doesNotContain("name").contains("no_secret");
    assertThat(doc.isVertex()).isTrue();
    // check that the property is visibilw when selected directly
    result = database.query("sql", "SELECT name FROM testHiddenProperty");
    assertThat(result.hasNext()).isTrue();
    doc = result.next();
    assertThat(doc.getPropertyNames()).contains("name");
    assertThat(doc.isVertex()).isTrue();

  }

When the query if performed using * the result is not a vertex, while when not using * the type is correctly a vertex.

causes

In Projection to allow the filtering of hidden properties, we switched to use Document.detach() :

        record.getElement().ifPresent(doc -> {
          if (!excludes.contains(RID_PROPERTY)) {
            result.setProperty(RID_PROPERTY, doc.getIdentity());
          }
          if (!excludes.contains(Property.TYPE_PROPERTY)) {
            result.setProperty(Property.TYPE_PROPERTY, doc.getType().getName());
          }

          Document detached = doc.detach(true);
          result.setElement(detached);
        });

The detached doesn't preserve the type hierarchy and the Vertex is returned as a Document, losing relationships.

possible solutions

  • Create a hierarchy of DetachedDocument, DetachedVertex, DetachedEdge and use covariant/contravariant capabilities of Java: not working
  • remove support of hidden properties, keeping the SQL clause, but not handling it at runtime

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions