Ejemplo n.º 1
0
    internal static void PbIntoScanner <TBuilder>(
        TBuilder builder, ScanTokenPB scanTokenPb)
        where TBuilder : AbstractKuduScannerBuilder <TBuilder>
    {
        var table  = builder.Table;
        var schema = table.Schema;

        if (scanTokenPb.FeatureFlags.Contains(ScanTokenPB.Types.Feature.Unknown))
        {
            throw new Exception("Scan token requires an unsupported feature. " +
                                "This Kudu client must be updated.");
        }

        builder.SetProjectedColumns(
            ComputeProjectedColumnIndexes(scanTokenPb, schema));

        foreach (var predicate in scanTokenPb.ColumnPredicates)
        {
            builder.AddPredicate(KuduPredicate.FromPb(schema, predicate));
        }

        if (scanTokenPb.HasLowerBoundPrimaryKey)
        {
            builder.LowerBoundRaw(scanTokenPb.LowerBoundPrimaryKey.ToByteArray());
        }

        if (scanTokenPb.HasUpperBoundPrimaryKey)
        {
            builder.ExclusiveUpperBoundRaw(scanTokenPb.UpperBoundPrimaryKey.ToByteArray());
        }

        if (scanTokenPb.HasLowerBoundPartitionKey)
        {
            builder.LowerBoundPartitionKeyRaw(scanTokenPb.LowerBoundPartitionKey.ToByteArray());
        }

        if (scanTokenPb.HasUpperBoundPartitionKey)
        {
            builder.ExclusiveUpperBoundPartitionKeyRaw(scanTokenPb.UpperBoundPartitionKey.ToByteArray());
        }

        if (scanTokenPb.HasLimit)
        {
            builder.SetLimit((long)scanTokenPb.Limit);
        }

        if (scanTokenPb.HasReadMode)
        {
            switch (scanTokenPb.ReadMode)
            {
            case Protobuf.ReadMode.ReadAtSnapshot:
            {
                builder.SetReadMode(ReadMode.ReadAtSnapshot);

                if (scanTokenPb.HasSnapTimestamp)
                {
                    builder.SnapshotTimestampRaw((long)scanTokenPb.SnapTimestamp);
                }

                // Set the diff scan timestamps if they are set.
                if (scanTokenPb.HasSnapStartTimestamp)
                {
                    builder.DiffScan(
                        (long)scanTokenPb.SnapStartTimestamp,
                        (long)scanTokenPb.SnapTimestamp);
                }

                break;
            }

            case Protobuf.ReadMode.ReadLatest:
            {
                builder.SetReadMode(ReadMode.ReadLatest);
                break;
            }

            case Protobuf.ReadMode.ReadYourWrites:
            {
                builder.SetReadMode(ReadMode.ReadYourWrites);
                break;
            }

            default:
                throw new Exception("Unknown read mode");
            }
        }

        if (scanTokenPb.HasReplicaSelection)
        {
            switch (scanTokenPb.ReplicaSelection)
            {
            case Protobuf.ReplicaSelection.LeaderOnly:
                builder.SetReplicaSelection(ReplicaSelection.LeaderOnly);
                break;

            case Protobuf.ReplicaSelection.ClosestReplica:
                builder.SetReplicaSelection(ReplicaSelection.ClosestReplica);
                break;

            default:
                throw new Exception("Unknown replica selection policy");
            }
        }

        if (scanTokenPb.HasPropagatedTimestamp &&
            (long)scanTokenPb.PropagatedTimestamp != KuduClient.NoTimestamp)
        {
            builder.Client.LastPropagatedTimestamp = (long)scanTokenPb.PropagatedTimestamp;
        }

        if (scanTokenPb.HasCacheBlocks)
        {
            builder.SetCacheBlocks(scanTokenPb.CacheBlocks);
        }

        if (scanTokenPb.HasFaultTolerant)
        {
            builder.SetFaultTolerant(scanTokenPb.FaultTolerant);
        }

        if (scanTokenPb.HasBatchSizeBytes)
        {
            builder.SetBatchSizeBytes((int)scanTokenPb.BatchSizeBytes);
        }

        if (scanTokenPb.HasScanRequestTimeoutMs)
        {
            // TODO
        }

        if (scanTokenPb.HasKeepAlivePeriodMs)
        {
            // TODO
        }
    }