use of org.apache.ignite.internal.util.GridStringBuilder in project ignite by apache.
the class GridQueryParsingTest method createTableToSql.
/**
* @param createTbl {@code CREATE TABLE} command.
* @return Corresponding SQL.
*/
private static String createTableToSql(GridSqlCreateTable createTbl) {
GridStringBuilder b = new SB("CREATE TABLE ").a(createTbl.ifNotExists() ? "IF NOT EXISTS " : "").a("\n").a(Parser.quoteIdentifier(createTbl.schemaName())).a('.').a(Parser.quoteIdentifier(createTbl.tableName())).a("\n(");
boolean singleColPk = false;
boolean first = true;
for (GridSqlColumn col : createTbl.columns().values()) {
if (!first)
b.a(",\n");
else
first = false;
if (col.column().isPrimaryKey()) {
// Only one column may be marked PRIMARY KEY - multi-col PK is defined separately
assert !singleColPk;
singleColPk = true;
}
b.a('\t').a(col.getSQL()).a(' ').a(col.resultType().sql()).a(col.column().isPrimaryKey() ? " PRIMARY KEY" : "");
}
first = true;
if (!singleColPk && !F.isEmpty(createTbl.primaryKeyColumns())) {
b.a(",\n").a('\t').a("PRIMARY KEY (\n");
for (String col : createTbl.primaryKeyColumns()) {
GridSqlColumn pkCol = createTbl.columns().get(col);
assert pkCol != null;
if (!first)
b.a(",\n");
else
first = false;
b.a("\t\t").a(pkCol.getSQL());
}
b.a("\n\t)");
}
b.a("\n)");
if (!F.isEmpty(createTbl.params())) {
b.a("\nWITH ");
first = true;
for (String p : createTbl.params()) {
if (!first)
b.a(',');
else
first = false;
b.a(Parser.quoteIdentifier(p));
}
}
return b.toString();
}
use of org.apache.ignite.internal.util.GridStringBuilder in project ignite by apache.
the class IgniteIndexReaderTest method insertQuery.
/**
* Performs an insert query.
*
* @param cache Ignite cache.
* @param tblName Table name.
* @param fields List of fields.
* @param cntr Counter which is used to generate data.
*/
private static void insertQuery(IgniteCache cache, String tblName, List<IgnitePair<String>> fields, int cntr) {
GridStringBuilder q = new GridStringBuilder().a("insert into ").a(tblName).a(" (id, ");
q.a(fields.stream().map(IgniteBiTuple::get1).collect(joining(", ")));
q.a(") values (");
q.a(fields.stream().map(f -> "?").collect(joining(", ", "?, ", ")")));
Object[] paramVals = new Object[fields.size() + 1];
for (int i = 0; i < fields.size() + 1; i++) paramVals[i] = (i % 2 == 0) ? cntr : valueOf(cntr);
query(cache, q.toString(), paramVals);
}
use of org.apache.ignite.internal.util.GridStringBuilder in project ignite by apache.
the class ProgressPrinter method printProgress0.
/**
*/
private void printProgress0(long curr, double currRatio) {
int progressBarLen = MIN_PROGRESS_BAR_LENGTH + (MAX_CAPTION_LENGTH - caption.length());
String progressBarFmt = "\r%s %4s [%" + progressBarLen + "s] %-50s";
int percentage = (int) (currRatio * 100);
int progressCurrLen = (int) (currRatio * progressBarLen);
long timeRunning = System.currentTimeMillis() - timeStarted;
long timeEstimated = (long) (timeRunning / currRatio);
GridStringBuilder progressBuilder = new GridStringBuilder();
for (int i = 0; i < progressBarLen; i++) progressBuilder.a(i < progressCurrLen ? "=" : " ");
long daysRunning = TimeUnit.MILLISECONDS.toDays(timeRunning);
long daysEstimated = TimeUnit.MILLISECONDS.toDays(timeEstimated);
String txtProgress = String.format("%s/%s (%s%s / %s%s)", curr, total, daysRunning > 0 ? daysRunning + " days " : "", formatDuration(timeRunning), daysEstimated > 0 ? daysEstimated + " days " : "", formatDuration(timeEstimated));
String progressBar = String.format(progressBarFmt, caption + ":", percentage + "%", progressBuilder.toString(), txtProgress);
printStream.print(progressBar);
}
use of org.apache.ignite.internal.util.GridStringBuilder in project ignite by apache.
the class IgniteIndexReader method printPagesListsInfo.
/**
* Prints page lists info.
*
* @param pageListsInfo Page lists info.
*/
private void printPagesListsInfo(PageListsInfo pageListsInfo) {
String prefix = PAGE_LISTS_PREFIX;
print("\n" + prefix + "Page lists info.");
if (!pageListsInfo.bucketsData.isEmpty())
print(prefix + "---Printing buckets data:");
pageListsInfo.bucketsData.forEach((bucket, bucketData) -> {
GridStringBuilder sb = new GridStringBuilder(prefix).a("List meta id=").a(bucket.get1()).a(", bucket number=").a(bucket.get2()).a(", lists=[").a(bucketData.stream().map(String::valueOf).collect(joining(", "))).a("]");
print(sb.toString());
});
printPageStat(prefix, "-- Page stat:", pageListsInfo.pageListStat);
printErrors(prefix, "---Errors:", "---No errors.", "Page id: %s, exception: ", true, pageListsInfo.errors);
print("");
print(prefix + "Total index pages found in lists: " + pageListsInfo.allPages.size());
print(prefix + "Total errors during lists scan: " + pageListsInfo.errors.size());
print("------------------");
}
use of org.apache.ignite.internal.util.GridStringBuilder in project ignite by apache.
the class SnapshotPartitionsVerifyHandler method complete.
/**
* {@inheritDoc}
*/
@Override
public void complete(String name, Collection<SnapshotHandlerResult<Map<PartitionKeyV2, PartitionHashRecordV2>>> results) throws IgniteCheckedException {
Map<PartitionKeyV2, List<PartitionHashRecordV2>> clusterHashes = new HashMap<>();
Map<ClusterNode, Exception> errs = new HashMap<>();
for (SnapshotHandlerResult<Map<PartitionKeyV2, PartitionHashRecordV2>> res : results) {
if (res.error() != null) {
errs.put(res.node(), res.error());
continue;
}
for (Map.Entry<PartitionKeyV2, PartitionHashRecordV2> entry : res.data().entrySet()) clusterHashes.computeIfAbsent(entry.getKey(), v -> new ArrayList<>()).add(entry.getValue());
}
IdleVerifyResultV2 verifyResult = new IdleVerifyResultV2(clusterHashes, errs);
if (errs.isEmpty() && !verifyResult.hasConflicts())
return;
GridStringBuilder buf = new GridStringBuilder();
verifyResult.print(buf::a, true);
throw new IgniteCheckedException(buf.toString());
}
Aggregations