Connection from C # to Accumulo

I am new to Accumulo. I need to read / write data from a remote Accumulo through C #. The only sample code / documentation for C # that I found is that the Accumulo range createBatchScanner is not working properly

I tried to compile the code in Xamarin Studio, on Mac.
The problem I am facing is related to this line:

AccumuloProxy.Client client = new AccumuloProxy.Client(protocol);

Error CS0246: type name or namespace AccumuloProxy' could not be found. Are you missingorg.apache.accumulo.proxy.thrift 'using the directive? (CS0246) (AccumuloIntegratorPrototype)

Where can I find DLLs to add to the CSharp project associated with the AccumuloProxy client? Is there a way that I can generate the same?

Here is the code snippet:

namespace AccumuloIntegratorPrototype
{
    class MainClass
    {
        static byte[] GetBytes(string str)
        {
            return Encoding.ASCII.GetBytes(str);
        }

        static string GetString(byte[] bytes)
        {
            return Encoding.ASCII.GetString(bytes);
        }

        public static void Main (string[] args)
        {
            try
            {
                /** connect **/
                TTransport transport = new TSocket("xxx.xx.x.xx", 42424);
                transport = new TFramedTransport(transport);
                TCompactProtocol protocol = new TCompactProtocol(transport);
                transport.Open();

                AccumuloProxy.Client client = new AccumuloProxy.Client(protocol);
0
2

.
.
.

. :
Accumulo 1.5
Thrift 0.90
Mono 3.2.5

. /, Accumulo #:
API - Accumulo

. Accumulo Proxy #:
node Accumulo
1. Mono 3.2.5
2. Thrift 0.90
3. - Accumulo
$ACCUMULO_HOME/proxy/proxy.properties;
, zookeeper
4. - -

${ACCUMULO_HOME}/bin/accumulo proxy -p ${ACCUMULO_HOME}/proxy/proxy.properties

5.Generated #, IDL proxy.thrift

thrift --gen csharp $ACCUMULO_HOME/proxy/thrift/proxy.thrift

gen-csharp ${ACCUMULO_HOME}/proxy/thrift/
6. gen-csharp #, D .
7. Thrift.dll .

. # - Accumulo:
1. .
2. gen-csharp C5,
3. ​​ thrift.dll
4.

E. Accumulo #
#, / Accumulo,
1. ​​ - thrift.dll
2. ​​ , D
3. Accumulo (. C4 )

, , .

using System;
using System.Text;
using System.Collections.Generic;

using Thrift.Protocol;
using Thrift.Transport;


namespace AccumuloIntegratorPrototype
{
class MainClass
{
    static byte[] GetBytes(string str)
    {
        return Encoding.ASCII.GetBytes(str);
    }


    static string GetString(byte[] bytes)
    {
        return Encoding.ASCII.GetString(bytes);
    }

    public static void Main (string[] args)
    {

        try
        {
            String accumuloProxyServerIP = "xxx.xxx.x.xx";//IP
            int accumuloProxyServerPort = 42424;//Port Number

            TTransport transport = new TSocket(accumuloProxyServerIP, accumuloProxyServerPort);
            transport = new TFramedTransport(transport);
            TCompactProtocol protocol = new TCompactProtocol(transport);
            transport.Open();

            String principal = "root";//Application ID
            Dictionary<string, string> passwd = new Dictionary<string,string>();
            passwd.Add("password", "xxxxx");//Password

            AccumuloProxy.Client client = new AccumuloProxy.Client(protocol);
            byte[] loginToken = client.login(principal, passwd);//Login token


            //{{
            //Read a range of rows from Accumulo
            var bScanner = new BatchScanOptions();
            Range range = new Range();

            range.Start = new Key();
            range.Start.Row = GetBytes("d001");

            //Need the \0 only if you need to get a single row back
            //Otherwise, its not needed
            range.Stop = new Key();
            range.Stop.Row = GetBytes("d001\0");

            bScanner.Ranges = new List<Range>();
            bScanner.Ranges.Add(range);

            String scanId = client.createBatchScanner(loginToken, "departments", bScanner);


            var more = true;
            while (more)
            {
                var scan = client.nextK(scanId, 10);
                more = scan.More;

                foreach (var entry in scan.Results)
                {
                    Console.WriteLine("Row = " + GetString(entry.Key.Row));
                    Console.WriteLine("{0} {1}:{2} [{3}]  {4}    {5}", GetString(entry.Key.Row), GetString(entry.Key.ColFamily), GetString(entry.Key.ColQualifier), GetString(entry.Key.ColVisibility), GetString(entry.Value),(long)entry.Key.Timestamp);
                }
            }

            client.closeScanner(scanId);

            client.Dispose();
            transport.Close();

            }catch (Exception e)
            {
                Console.WriteLine(e);
            }
        //}}



    }
}
}
+1

Thrift # :

  • #, Thrift
  • Thrift.DLL . , , .

# 1 IDL Thrift, . IDL proxy/src/main/thrift Accumulo.

Thrift http://thrift.apache.org. , Apache Thrift, . elserj, Accumulo 1.4.x Thrift 0.6.1, Accumulo 1.5.x Thrift 0.9.0.

0

All Articles