Search in sources :

Example 1 with GridStringBuilder

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();
}
Also used : GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 2 with GridStringBuilder

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);
}
Also used : GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple)

Example 3 with GridStringBuilder

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);
}
Also used : GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder)

Example 4 with GridStringBuilder

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("------------------");
}
Also used : GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder)

Example 5 with GridStringBuilder

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());
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) PartitionKeyV2(org.apache.ignite.internal.processors.cache.verify.PartitionKeyV2) PartitionHashRecordV2(org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2) ArrayList(java.util.ArrayList) List(java.util.List) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

GridStringBuilder (org.apache.ignite.internal.util.GridStringBuilder)19 SB (org.apache.ignite.internal.util.typedef.internal.SB)8 Map (java.util.Map)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteException (org.apache.ignite.IgniteException)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Ignite (org.apache.ignite.Ignite)1 IgniteCluster (org.apache.ignite.IgniteCluster)1 BinaryObject (org.apache.ignite.binary.BinaryObject)1 QueryEntity (org.apache.ignite.cache.QueryEntity)1 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)1