Search in sources :

Example 21 with MetaDataResponse

use of org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataResponse in project phoenix by apache.

the class ConnectionQueryServicesImpl method createSchema.

@Override
public MetaDataMutationResult createSchema(final List<Mutation> schemaMutations, final String schemaName) throws SQLException {
    ensureNamespaceCreated(schemaName);
    Mutation m = MetaDataUtil.getPutOnlyTableHeaderRow(schemaMutations);
    byte[] key = m.getRow();
    MetaDataMutationResult result = metaDataCoprocessorExec(key, new Batch.Call<MetaDataService, MetaDataResponse>() {

        @Override
        public MetaDataResponse call(MetaDataService instance) throws IOException {
            ServerRpcController controller = new ServerRpcController();
            BlockingRpcCallback<MetaDataResponse> rpcCallback = new BlockingRpcCallback<MetaDataResponse>();
            CreateSchemaRequest.Builder builder = CreateSchemaRequest.newBuilder();
            for (Mutation m : schemaMutations) {
                MutationProto mp = ProtobufUtil.toProto(m);
                builder.addTableMetadataMutations(mp.toByteString());
            }
            builder.setSchemaName(schemaName);
            builder.setClientVersion(VersionUtil.encodeVersion(PHOENIX_MAJOR_VERSION, PHOENIX_MINOR_VERSION, PHOENIX_PATCH_NUMBER));
            instance.createSchema(controller, builder.build(), rpcCallback);
            if (controller.getFailedOn() != null) {
                throw controller.getFailedOn();
            }
            return rpcCallback.get();
        }
    });
    return result;
}
Also used : MetaDataResponse(org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataResponse) KeyValueBuilder(org.apache.phoenix.hbase.index.util.KeyValueBuilder) NonTxIndexBuilder(org.apache.phoenix.hbase.index.covered.NonTxIndexBuilder) PhoenixIndexBuilder(org.apache.phoenix.index.PhoenixIndexBuilder) IOException(java.io.IOException) PhoenixIOException(org.apache.phoenix.exception.PhoenixIOException) ServerRpcController(org.apache.hadoop.hbase.ipc.ServerRpcController) MutationProto(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto) MetaDataService(org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataService) Batch(org.apache.hadoop.hbase.client.coprocessor.Batch) BlockingRpcCallback(org.apache.hadoop.hbase.ipc.BlockingRpcCallback) Mutation(org.apache.hadoop.hbase.client.Mutation) MetaDataMutationResult(org.apache.phoenix.coprocessor.MetaDataProtocol.MetaDataMutationResult)

Aggregations

MetaDataResponse (org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataResponse)21 Mutation (org.apache.hadoop.hbase.client.Mutation)16 IOException (java.io.IOException)14 BlockingRpcCallback (org.apache.hadoop.hbase.ipc.BlockingRpcCallback)12 ServerRpcController (org.apache.hadoop.hbase.ipc.ServerRpcController)12 MetaDataService (org.apache.phoenix.coprocessor.generated.MetaDataProtos.MetaDataService)12 KeyValueBuilder (org.apache.phoenix.hbase.index.util.KeyValueBuilder)12 Batch (org.apache.hadoop.hbase.client.coprocessor.Batch)11 MutationProto (org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto)11 PhoenixIOException (org.apache.phoenix.exception.PhoenixIOException)10 NonTxIndexBuilder (org.apache.phoenix.hbase.index.covered.NonTxIndexBuilder)9 PhoenixIndexBuilder (org.apache.phoenix.index.PhoenixIndexBuilder)9 Region (org.apache.hadoop.hbase.regionserver.Region)8 MetaDataMutationResult (org.apache.phoenix.coprocessor.MetaDataProtocol.MetaDataMutationResult)8 RowLock (org.apache.hadoop.hbase.regionserver.Region.RowLock)6 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)6 ByteString (com.google.protobuf.ByteString)5 ArrayList (java.util.ArrayList)5 PMetaDataEntity (org.apache.phoenix.schema.PMetaDataEntity)5 PTable (org.apache.phoenix.schema.PTable)5