Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BooleanSupplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteServer;
import org.apache.ignite.InitParameters;
Expand Down Expand Up @@ -457,20 +456,28 @@ public String createZoneSQL() {
secondaryStorageProfile;

String storageProfiles = useColumnar ?
String.join(",", storageProfile, secondaryStorageProfile) :
String.join("', '", storageProfile, secondaryStorageProfile) :
storageProfile;

String paramStorageProfiles = String.format("STORAGE_PROFILES='%s'", storageProfiles);
String paramReplicas = replicas.isEmpty() ? "" : "replicas=" + replicas;
String paramPartitions = partitions.isEmpty() ? "" : "partitions=" + partitions;
String paramNodesFilter = nodesFilter.isEmpty() ? "" :
String.format("DATA_NODES_FILTER='$[?(@.%s == \"%s\")]'", NODES_FILTER_ATTRIBUTE, nodesFilter);
String params = Stream.of(paramStorageProfiles, paramReplicas, paramPartitions, paramNodesFilter)
.filter(s -> !s.isEmpty())
.collect(Collectors.joining(", "));
String reqWithParams = params.isEmpty() ? "" : " WITH " + params;
List<String> params = new ArrayList<>();

if (!replicas.isEmpty()) {
params.add("replicas " + replicas);
}

if (!partitions.isEmpty()) {
params.add("partitions " + partitions);
}

if (!nodesFilter.isEmpty()) {
params.add(String.format("NODES FILTER '$[?(@.%s == \"%s\")]'", NODES_FILTER_ATTRIBUTE, nodesFilter));
}

String paramsStr = params.isEmpty() ? "" : " (" + String.join(", ", params) + ")";

String storageProfilesStr = String.format(" STORAGE PROFILES ['%s']", storageProfiles);

return String.format("CREATE ZONE IF NOT EXISTS %s%s;", zoneName, reqWithParams);
return String.format("CREATE ZONE IF NOT EXISTS %s%s%s;", zoneName, paramsStr, storageProfilesStr);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,56 @@ public class IgniteAbstractClientTest {
public static Properties properties() {
Properties result = new Properties();

result.put("hosts","192.168.209.148");
result.put("hosts", "192.168.209.148");

return result;
}

@Test
public void testCreateDdl() throws DBException {
doTestCreateDdl(
"CREATE ZONE IF NOT EXISTS Z1 WITH STORAGE_PROFILES='default,myColumnarStore';",
List.of(CREATE_TABLE_DDL +
" ZONE \"Z1\" STORAGE PROFILE 'default' SECONDARY ZONE \"Z1\" SECONDARY STORAGE PROFILE 'myColumnarStore'"),
true);
Properties properties = properties();

doTestCreateDdl(
"",
List.of(CREATE_TABLE_DDL),
false);
properties);
}

@Test
public void testCreateDdlWithColumnar() throws DBException {
Properties properties = properties();

properties.put("useColumnar", String.valueOf(true));

doTestCreateDdl(
"CREATE ZONE IF NOT EXISTS Z1 STORAGE PROFILES ['default', 'myColumnarStore'];",
List.of(CREATE_TABLE_DDL +
" ZONE \"Z1\" STORAGE PROFILE 'default' SECONDARY ZONE \"Z1\" SECONDARY STORAGE PROFILE 'myColumnarStore'"),
properties);
}

@Test
public void testCreateDdlWithReplicasAndPartitionsAndNodesFilter() throws DBException {
Properties properties = properties();

properties.put("useColumnar", String.valueOf(false));
properties.put("replicas", "1");
properties.put("partitions", "2");
properties.put("nodesFilter", "test_filter");

doTestCreateDdl(
"CREATE ZONE IF NOT EXISTS Z1 "
+ "(replicas 1, partitions 2, NODES FILTER '$[?(@.ycsbFilter == \"test_filter\")]') STORAGE PROFILES ['default'];",
List.of(CREATE_TABLE_DDL + " ZONE \"Z1\""),
properties);
}

public void doTestCreateDdl(
String createZoneDdlExpected,
List<String> createTableDdlExpected,
boolean useColumnar
Properties properties
) throws DBException {
IgniteAbstractClient client = new IgniteClient();
Properties properties = properties();
properties.put("useColumnar", String.valueOf(useColumnar));
client.initProperties(properties);

String createZoneDdlActual = client.createZoneSQL();
Expand Down