use of com.datastax.dse.driver.api.core.metadata.schema.DseEdgeMetadata in project dsbulk by datastax.
the class SchemaSettingsTest method should_error_when_edge_non_existent_but_lower_case_variant_exists.
@Test
void should_error_when_edge_non_existent_but_lower_case_variant_exists() {
DseEdgeMetadata edgeMetadata = mock(DseEdgeMetadata.class);
when(table.getEdge()).thenAnswer(x -> Optional.of(edgeMetadata));
when(edgeMetadata.getLabelName()).thenReturn(CqlIdentifier.fromInternal("e1"));
when(edgeMetadata.getFromLabel()).thenReturn(CqlIdentifier.fromInternal("v1"));
when(edgeMetadata.getToLabel()).thenReturn(CqlIdentifier.fromInternal("V2"));
Config config = TestConfigUtils.createTestConfig("dsbulk.schema", "graph", "ks", "edge", "\"E1\"", "from", "\"V1\"", "to", "\"V2\"");
SchemaSettings settings = new SchemaSettings(config, MAP_AND_WRITE);
assertThatThrownBy(() -> settings.init(session, codecFactory, true, false)).isInstanceOf(IllegalArgumentException.class).hasMessage("Edge label \"E1\" from \"V1\" to \"V2\" does not exist, however an edge label e1 from v1 to \"V2\" was found. Did you mean to use -e e1 -from v1 -to \"V2\"?");
}
use of com.datastax.dse.driver.api.core.metadata.schema.DseEdgeMetadata in project dsbulk by datastax.
the class SchemaSettings method locateEdgeTable.
@NonNull
private TableMetadata locateEdgeTable(KeyspaceMetadata keyspace, String edgeLabelInternal, String fromVertexInternal, String toVertexInternal) {
CqlIdentifier edgeLabel = CqlIdentifier.fromInternal(edgeLabelInternal);
CqlIdentifier fromVertex = CqlIdentifier.fromInternal(fromVertexInternal);
CqlIdentifier toVertex = CqlIdentifier.fromInternal(toVertexInternal);
Optional<DseGraphTableMetadata> edge = allEdgeTables(keyspace).filter(table -> table.getEdge().get().getLabelName().equals(edgeLabel)).filter(table -> table.getEdge().get().getFromLabel().equals(fromVertex)).filter(table -> table.getEdge().get().getToLabel().equals(toVertex)).findFirst();
if (!edge.isPresent()) {
Optional<? extends DseEdgeMetadata> match = allEdgeTables(keyspace).map(DseGraphTableMetadata::getEdge).filter(e -> e.get().getLabelName().asInternal().equalsIgnoreCase(edgeLabelInternal)).filter(e -> e.get().getFromLabel().asInternal().equalsIgnoreCase(fromVertexInternal)).filter(e -> e.get().getToLabel().asInternal().equalsIgnoreCase(toVertexInternal)).map(Optional::get).findFirst();
if (match.isPresent()) {
DseEdgeMetadata edgeMetadata = match.get();
String similarLabel = edgeMetadata.getLabelName().asCql(true);
String similarFrom = edgeMetadata.getFromLabel().asCql(true);
String similarTo = edgeMetadata.getToLabel().asCql(true);
throw new IllegalArgumentException(String.format("Edge label %s from %s to %s does not exist, " + "however an edge label %s from %s to %s was found. " + "Did you mean to use -e %s -from %s -to %s?", edgeLabel.asCql(true), fromVertex.asCql(true), toVertex.asCql(true), similarLabel, similarFrom, similarTo, similarLabel, similarFrom, similarTo));
} else {
throw new IllegalArgumentException(String.format("Edge label %s from %s to %s does not exist", edgeLabel.asCql(true), fromVertex.asCql(true), toVertex.asCql(true)));
}
}
return edge.get();
}
use of com.datastax.dse.driver.api.core.metadata.schema.DseEdgeMetadata in project dsbulk by datastax.
the class SchemaSettingsTest method should_locate_existing_edge_label.
@Test
void should_locate_existing_edge_label() {
DseEdgeMetadata edgeMetadata = mock(DseEdgeMetadata.class);
when(table.getEdge()).thenAnswer(x -> Optional.of(edgeMetadata));
when(edgeMetadata.getLabelName()).thenReturn(CqlIdentifier.fromInternal("e1"));
when(edgeMetadata.getFromLabel()).thenReturn(CqlIdentifier.fromInternal("v1"));
when(edgeMetadata.getToLabel()).thenReturn(CqlIdentifier.fromInternal("v2"));
when(keyspace.getGraphEngine()).thenReturn(Optional.of("Core"));
Config config = TestConfigUtils.createTestConfig("dsbulk.schema", "graph", "ks", "edge", "e1", "from", "v1", "to", "v2");
SchemaSettings settings = new SchemaSettings(config, MAP_AND_WRITE);
settings.init(session, codecFactory, true, false);
assertThat(getInternalState(settings, "table")).isSameAs(table);
}
Aggregations