static SchemaParser forDseVersion(VersionNumber dseVersion) { if (dseVersion.getMajor() >= 5) return V3_PARSER; return V2_PARSER; }
/** * Based on C* version, return the wait arguments. * * @return For C* 1.x, --wait-other-notice otherwise --no-wait */ private String getStartWaitArguments() { // make a small exception for C* 1.2 as it has a bug where it starts listening on the binary // interface slightly before it joins the cluster. if (this.cassandraVersion.getMajor() == 1) { return " --wait-other-notice"; } else { return " --no-wait"; } }
private static int findClusteringSize( DataTypeClassNameParser.ParseResult comparator, Collection<ColumnMetadata.Raw> cols, List<String> columnAliases, VersionNumber cassandraVersion) { // In 2.0 onwards, this is relatively easy, we just find the biggest 'position' amongst the // clustering columns. // For 1.2 however, this is slightly more subtle: we need to infer it based on whether the // comparator is composite or not, and whether we have // regular columns or not. if (cassandraVersion.getMajor() >= 2) { int maxId = -1; for (ColumnMetadata.Raw col : cols) if (col.kind == ColumnMetadata.Raw.Kind.CLUSTERING_COLUMN) maxId = Math.max(maxId, col.position); return maxId + 1; } else { int size = comparator.types.size(); if (comparator.isComposite) return !comparator.collections.isEmpty() || (columnAliases.size() == size - 1 && comparator.types.get(size - 1).equals(DataType.text())) ? size - 1 : size; else // We know cols only has the REGULAR ones for 1.2 return !columnAliases.isEmpty() || cols.isEmpty() ? size : 0; } }
private static Map<String, DataType> buildArguments( KeyspaceMetadata ksm, List<String> names, List<String> types, VersionNumber version, Cluster cluster) { if (names.isEmpty()) return Collections.emptyMap(); ImmutableMap.Builder<String, DataType> builder = ImmutableMap.builder(); CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry(); ProtocolVersion protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion(); Iterator<String> iterTypes = types.iterator(); for (String name : names) { DataType type; if (version.getMajor() >= 3) { type = DataTypeCqlNameParser.parse( iterTypes.next(), cluster, ksm.getName(), ksm.userTypes, null, false, false); } else { type = DataTypeClassNameParser.parseOne(iterTypes.next(), protocolVersion, codecRegistry); } builder.put(name, type); } return builder.build(); }
private static List<DataType> parseTypes( KeyspaceMetadata ksm, List<String> types, VersionNumber version, Cluster cluster) { if (types.isEmpty()) return Collections.emptyList(); CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry(); ProtocolVersion protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion(); ImmutableList.Builder<DataType> builder = ImmutableList.builder(); for (String name : types) { DataType type; if (version.getMajor() >= 3) { type = DataTypeCqlNameParser.parse( name, cluster, ksm.getName(), ksm.userTypes, null, false, false); } else { type = DataTypeClassNameParser.parseOne(name, protocolVersion, codecRegistry); } builder.add(type); } return builder.build(); }
@BeforeMethod(groups = "short") public void sleepIf12() { // For C* 1.2, sleep before attempting to connect as there is a small delay between // user being created. if (ccm().getCassandraVersion().getMajor() < 2) { Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); } }
static KeyspaceMetadata build(Row row, VersionNumber cassandraVersion) { if (cassandraVersion.getMajor() <= 2) { String name = row.getString(KS_NAME); boolean durableWrites = row.getBool(DURABLE_WRITES); Map<String, String> replicationOptions; replicationOptions = new HashMap<String, String>(); replicationOptions.put("class", row.getString(STRATEGY_CLASS)); replicationOptions.putAll(SimpleJSONParser.parseStringMap(row.getString(STRATEGY_OPTIONS))); return new KeyspaceMetadata(name, durableWrites, replicationOptions, false); } else { String name = row.getString(KS_NAME); boolean durableWrites = row.getBool(DURABLE_WRITES); return new KeyspaceMetadata( name, durableWrites, row.getMap(REPLICATION, String.class, String.class), false); } }
if (version.getMajor() < 2) { kind = Kind.REGULAR; } else if (version.getMajor() < 3) { kind = row.isNull(KIND_V2) ? Kind.REGULAR : Kind.fromStringV2(row.getString(KIND_V2)); } else { if (version.getMajor() >= 3) { position = row.getInt( if (version.getMajor() >= 3) { dataType = row.getString(TYPE); String clusteringOrderStr = row.getString(CLUSTERING_ORDER); if (version.getMajor() < 3) { for (String str : Arrays.asList(INDEX_TYPE, INDEX_NAME, INDEX_OPTIONS)) if (row.getColumnDefinitions().contains(str) && !row.isNull(str))
static UserType build( KeyspaceMetadata ksm, Row row, VersionNumber version, Cluster cluster, Map<String, UserType> userTypes) { ProtocolVersion protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion(); CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry(); String keyspace = row.getString(KeyspaceMetadata.KS_NAME); String name = row.getString(TYPE_NAME); List<String> fieldNames = row.getList(COLS_NAMES, String.class); List<String> fieldTypes = row.getList(COLS_TYPES, String.class); List<Field> fields = new ArrayList<Field>(fieldNames.size()); for (int i = 0; i < fieldNames.size(); i++) { DataType fieldType; if (version.getMajor() >= 3.0) { fieldType = DataTypeCqlNameParser.parse( fieldTypes.get(i), cluster, ksm.getName(), userTypes, ksm.userTypes, false, false); } else { fieldType = DataTypeClassNameParser.parseOne(fieldTypes.get(i), protocolVersion, codecRegistry); } fields.add(new Field(fieldNames.get(i), fieldType)); } return new UserType(keyspace, name, false, fields, protocolVersion, codecRegistry); }
public VersionNumberAssert hasMajorMinorPatch(int major, int minor, int patch) { assertThat(actual.getMajor()).isEqualTo(major); assertThat(actual.getMinor()).isEqualTo(minor); assertThat(actual.getPatch()).isEqualTo(patch); return this; }
private String getExpectedCqlString() { String majorMinor = ccm().getCassandraVersion().getMajor() + "." + ccm().getCassandraVersion().getMinor(); String resourceName = "/export_as_string_test_" + majorMinor + ".cql";
@Test(groups = "short", expectedExceptions = UnsupportedFeatureException.class) @CassandraVersion("2.0.0") public void should_fail_if_query_with_named_values_if_protocol_is_V1() { if (ccm().getCassandraVersion().getMajor() >= 3) { throw new SkipException("Skipping since Cassandra 3.0+ does not support protocol v1"); } useNamedValuesWithProtocol(ProtocolVersion.V1); } }
@Test(groups = "short", expectedExceptions = UnsupportedFeatureException.class) @CassandraVersion("2.0.0") public void should_fail_if_query_with_named_values_if_protocol_is_V2() { if (ccm().getCassandraVersion().getMajor() >= 3) { throw new SkipException("Skipping since Cassandra 3.0+ does not support protocol v2"); } useNamedValuesWithProtocol(ProtocolVersion.V2); }
/** * @return The mapped cassandra version to the given dseVersion. If the DSE version can't be * derived the following logic is used: * <ol> * <li>If <= 3.X, use C* 1.2 * <li>If 4.X, use 2.1 for >= 4.7, 2.0 otherwise. * <li>Otherwise 3.0 * </ol> */ public static VersionNumber getCassandraVersion(VersionNumber dseVersion) { String cassandraVersion = dseToCassandraVersions.get(dseVersion.toString()); if (cassandraVersion != null) { return VersionNumber.parse(cassandraVersion); } else if (dseVersion.getMajor() <= 3) { return VersionNumber.parse("1.2"); } else if (dseVersion.getMajor() == 4) { if (dseVersion.getMinor() >= 7) { return VersionNumber.parse("2.1"); } else { return VersionNumber.parse("2.0"); } } else { // Fallback on 3.0 by default. return VersionNumber.parse("3.0"); } }
@Test(groups = "short") @CassandraVersion("2.1.0") public void should_create_metadata_for_index_on_map_values() { // 3.0 assumes the 'values' keyword if index on a collection String createValuesIndex = ccm().getCassandraVersion().getMajor() > 2 ? String.format( "CREATE INDEX map_values_index ON %s.indexing (values(map_values));", keyspace) : String.format("CREATE INDEX map_values_index ON %s.indexing (map_values);", keyspace); session().execute(createValuesIndex); ColumnMetadata column = getColumn("map_values"); IndexMetadata index = getIndex("map_values_index"); assertThat(index) .hasName("map_values_index") .hasParent((TableMetadata) column.getParent()) .isNotCustomIndex() .hasTarget(ccm().getCassandraVersion().getMajor() > 2 ? "values(map_values)" : "map_values") .hasKind(COMPOSITES) .asCqlQuery(createValuesIndex); assertThat((TableMetadata) column.getParent()).hasIndex(index); }
@Test(groups = "short") @CassandraVersion( value = "2.1", description = "index names with quoted identifiers and collection indexes not supported until 2.1") public void should_create_metadata_for_values_index_on_mixed_case_column() { // 3.0 assumes the 'values' keyword if index on a collection String createValuesIndex = ccm().getCassandraVersion().getMajor() > 2 ? String.format( "CREATE INDEX \"MixedCaseIndex\" ON %s.indexing (values(\"MixedCaseColumn\"));", keyspace) : String.format( "CREATE INDEX \"MixedCaseIndex\" ON %s.indexing (\"MixedCaseColumn\");", keyspace); session().execute(createValuesIndex); ColumnMetadata column = getColumn("\"MixedCaseColumn\""); IndexMetadata index = getIndex("\"MixedCaseIndex\""); assertThat(index) .hasName("MixedCaseIndex") .hasParent((TableMetadata) column.getParent()) .isNotCustomIndex() .hasTarget( ccm().getCassandraVersion().getMajor() > 2 ? "values(\"MixedCaseColumn\")" : "\"MixedCaseColumn\"") .hasKind(COMPOSITES) .asCqlQuery(createValuesIndex); assertThat((TableMetadata) column.getParent()).hasIndex(index); }
/** * Validates aggregates with DynamicCompositeType state types and an initcond value that is a * literal, i.e.: 's@foo:i@32' can be appropriately parsed and generate a CQL string with the init * cond as a hex string, i.e.: 0x80730003666f6f00806900040000002000. * * @jira_ticket JAVA-1046 * @test_category metadata * @since 3.0.1 */ @Test(groups = "short") @CassandraVersion("2.2.0") public void should_parse_and_format_aggregate_with_composite_type_literal_initcond() { VersionNumber ver = ccm().getCassandraVersion(); if (ver.getMajor() == 3) { if ((ver.getMinor() >= 1 && ver.getMinor() < 4) || (ver.getMinor() == 0 && ver.getPatch() < 4)) { throw new SkipException("Requires C* 2.2.X, 3.0.4+ or 3.4.X+"); } } parse_and_format_aggregate_with_composite_type("ag0", "'s@foo:i@32'"); }