Search in sources :

Example 1 with DseEdgeMetadata

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\"?");
}
Also used : DseEdgeMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseEdgeMetadata) Config(com.typesafe.config.Config) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 2 with DseEdgeMetadata

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();
}
Also used : MAPPED_OR_INDEXED(com.datastax.oss.dsbulk.mapping.MappingPreference.MAPPED_OR_INDEXED) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) MAPPED_ONLY(com.datastax.oss.dsbulk.mapping.MappingPreference.MAPPED_ONLY) DefaultMapping(com.datastax.oss.dsbulk.mapping.DefaultMapping) GenericType(com.datastax.oss.driver.api.core.type.reflect.GenericType) TokenRangeReadStatementGenerator(com.datastax.oss.dsbulk.partitioner.TokenRangeReadStatementGenerator) ConfigUtils(com.datastax.oss.dsbulk.config.ConfigUtils) ALIASED_SELECTOR(com.datastax.oss.dsbulk.mapping.CQLRenderMode.ALIASED_SELECTOR) BatchType(com.datastax.oss.driver.api.core.cql.BatchType) Map(java.util.Map) VisibleForTesting(com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting) ProtocolVersion(com.datastax.oss.driver.api.core.ProtocolVersion) EnumSet(java.util.EnumSet) CQLRenderMode(com.datastax.oss.dsbulk.mapping.CQLRenderMode) VARIABLE(com.datastax.oss.dsbulk.mapping.CQLRenderMode.VARIABLE) MapType(com.datastax.oss.driver.api.core.type.MapType) GraphUtils(com.datastax.oss.dsbulk.workflow.commons.utils.GraphUtils) Set(java.util.Set) ImmutableList(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList) Field(com.datastax.oss.dsbulk.connectors.api.Field) Stream(java.util.stream.Stream) ConfigException(com.typesafe.config.ConfigException) CQLWord(com.datastax.oss.dsbulk.mapping.CQLWord) INDEXED_ONLY(com.datastax.oss.dsbulk.mapping.MappingPreference.INDEXED_ONLY) MICROSECONDS(java.util.concurrent.TimeUnit.MICROSECONDS) CQLLiteral(com.datastax.oss.dsbulk.mapping.CQLLiteral) ImmutableSet(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableSet) Preconditions(com.datastax.oss.driver.shaded.guava.common.base.Preconditions) STAR(com.datastax.oss.dsbulk.mapping.MappingInspector.STAR) ViewMetadata(com.datastax.oss.driver.api.core.metadata.schema.ViewMetadata) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) CqlSession(com.datastax.oss.driver.api.core.CqlSession) DefaultReadResultMapper(com.datastax.oss.dsbulk.workflow.commons.schema.DefaultReadResultMapper) FunctionCall(com.datastax.oss.dsbulk.mapping.FunctionCall) StreamSupport(java.util.stream.StreamSupport) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) LinkedHashSet(java.util.LinkedHashSet) DseEdgeMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseEdgeMetadata) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) RelationMetadata(com.datastax.oss.driver.api.core.metadata.schema.RelationMetadata) MappingPreference(com.datastax.oss.dsbulk.mapping.MappingPreference) Config(com.typesafe.config.Config) NestedBatchException(com.datastax.oss.dsbulk.workflow.commons.schema.NestedBatchException) DataType(com.datastax.oss.driver.api.core.type.DataType) ConvertingCodecFactory(com.datastax.oss.dsbulk.codecs.api.ConvertingCodecFactory) DefaultRecordMapper(com.datastax.oss.dsbulk.workflow.commons.schema.DefaultRecordMapper) RecordMapper(com.datastax.oss.dsbulk.workflow.commons.schema.RecordMapper) DseTableMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseTableMetadata) CQLFragment(com.datastax.oss.dsbulk.mapping.CQLFragment) WRITETIME(com.datastax.oss.dsbulk.mapping.MappingInspector.WRITETIME) ReadResultMapper(com.datastax.oss.dsbulk.workflow.commons.schema.ReadResultMapper) DseVertexMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseVertexMetadata) Nullable(edu.umd.cs.findbugs.annotations.Nullable) StatisticsMode(com.datastax.oss.dsbulk.workflow.commons.settings.StatsSettings.StatisticsMode) DefaultReadResultCounter(com.datastax.oss.dsbulk.workflow.commons.schema.DefaultReadResultCounter) CodecUtils.instantToNumber(com.datastax.oss.dsbulk.codecs.api.util.CodecUtils.instantToNumber) IndexedMappingField(com.datastax.oss.dsbulk.mapping.IndexedMappingField) LoggerFactory(org.slf4j.LoggerFactory) MappingField(com.datastax.oss.dsbulk.mapping.MappingField) QueryInspector(com.datastax.oss.dsbulk.workflow.commons.schema.QueryInspector) Mapping(com.datastax.oss.dsbulk.mapping.Mapping) ReadResultCounter(com.datastax.oss.dsbulk.workflow.commons.schema.ReadResultCounter) Lists(com.datastax.oss.driver.shaded.guava.common.collect.Lists) ConvertingCodec(com.datastax.oss.dsbulk.codecs.api.ConvertingCodec) NonNull(edu.umd.cs.findbugs.annotations.NonNull) Predicates(com.datastax.oss.driver.shaded.guava.common.base.Predicates) URI(java.net.URI) IndexMetadata(com.datastax.oss.driver.api.core.metadata.schema.IndexMetadata) Record(com.datastax.oss.dsbulk.connectors.api.Record) ImmutableMultimap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMultimap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) NAMED_ASSIGNMENT(com.datastax.oss.dsbulk.mapping.CQLRenderMode.NAMED_ASSIGNMENT) Objects(java.util.Objects) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) DataTypes(com.datastax.oss.driver.api.core.type.DataTypes) List(java.util.List) Entry(java.util.Map.Entry) Optional(java.util.Optional) SetType(com.datastax.oss.driver.api.core.type.SetType) TIMESTAMP_PATTERN(com.datastax.oss.dsbulk.codecs.api.CommonConversionContext.TIMESTAMP_PATTERN) MappingInspector(com.datastax.oss.dsbulk.mapping.MappingInspector) DseGraphKeyspaceMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseGraphKeyspaceMetadata) ListType(com.datastax.oss.driver.api.core.type.ListType) HashSet(java.util.HashSet) RecordMetadata(com.datastax.oss.dsbulk.connectors.api.RecordMetadata) ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) MappedMappingField(com.datastax.oss.dsbulk.mapping.MappedMappingField) ImmutableSetMultimap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableSetMultimap) INTERNAL(com.datastax.oss.dsbulk.mapping.CQLRenderMode.INTERNAL) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) TypedCQLLiteral(com.datastax.oss.dsbulk.mapping.TypedCQLLiteral) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) DseGraphTableMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseGraphTableMetadata) ColumnMetadata(com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata) DefaultProtocolVersion(com.datastax.oss.driver.api.core.DefaultProtocolVersion) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) TTL(com.datastax.oss.dsbulk.mapping.MappingInspector.TTL) Multimap(com.datastax.oss.driver.shaded.guava.common.collect.Multimap) EPOCH(java.time.Instant.EPOCH) Collections(java.util.Collections) Statement(com.datastax.oss.driver.api.core.cql.Statement) DseEdgeMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseEdgeMetadata) DseGraphTableMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseGraphTableMetadata) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 3 with DseEdgeMetadata

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);
}
Also used : DseEdgeMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseEdgeMetadata) Config(com.typesafe.config.Config) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

DseEdgeMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseEdgeMetadata)3 Config (com.typesafe.config.Config)3 DseGraphKeyspaceMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseGraphKeyspaceMetadata)1 DseGraphTableMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseGraphTableMetadata)1 DseTableMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseTableMetadata)1 DseVertexMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseVertexMetadata)1 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)1 CqlSession (com.datastax.oss.driver.api.core.CqlSession)1 DefaultProtocolVersion (com.datastax.oss.driver.api.core.DefaultProtocolVersion)1 ProtocolVersion (com.datastax.oss.driver.api.core.ProtocolVersion)1 BatchType (com.datastax.oss.driver.api.core.cql.BatchType)1 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)1 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)1 Statement (com.datastax.oss.driver.api.core.cql.Statement)1 Metadata (com.datastax.oss.driver.api.core.metadata.Metadata)1 ColumnMetadata (com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata)1 IndexMetadata (com.datastax.oss.driver.api.core.metadata.schema.IndexMetadata)1 KeyspaceMetadata (com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)1 RelationMetadata (com.datastax.oss.driver.api.core.metadata.schema.RelationMetadata)1 TableMetadata (com.datastax.oss.driver.api.core.metadata.schema.TableMetadata)1