Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Creating a thrift hive client in C# but the hive client hangs, on recv_execute

Creating a thrift hive client in C# but the hive client hangs, on recv_execute

New Contributor

hi, 

I am creating a thrift hive client in C# and the server is a hadoop hive server2... I am able to connect to the server and perform SASL Authentication.

But when i call client.send_execute("show tables;") and then client.recv_execute(), it doesn't send the list of tables...

basically code hangs on recv_execute() waiting on incoming connection and data never comes in....

 

s some thing wrong here, am I missing some thing (code below).

 

i have tried TCLIService still it hangs on receiving session...

 

I am using hive-sharp-lib.... and Cloudera Distribution

 
var socket = new TSocket("xxx.xxx.xxx.xxx", 10000, 60000);        socket.Timeout = 9999999;
        TStreamTransport sTransport = (TStreamTransport)socket;
        var transport =  new TSaslClientTransport(new TBufferedTransport(sTransport));

        var proto = new TBinaryProtocol(transport);

        var client = new ThriftHive.Client(proto);        transport.Open();        client.send_execute("show tables;");        client.recv_execute();

Code of TSaslClientTransport.cs

 

using System;using System.Collections.Generic;using System.Linq;using System.Text;using S22.Sasl.Mechanisms;namespace Thrift.Transport
{
public class TSaslClientTransport : TTransport
{
    byte START = 0x01;
    byte OK = 0x02;
    byte BAD = 0x03;
    byte ERROR = 0x04;
    byte COMPLETE = 0x05;

    protected TTransport underlyingTransport;
    byte[] messageHeader = new byte[1 + 4];

    int SWITCH_TO_SIMPLE_AUTH = -88;

    public TSaslClientTransport(TTransport underlyingTransport)
    {
        this.underlyingTransport = underlyingTransport;
    }
    public override bool IsOpen
    {        get { throw new NotImplementedException(); }
    }

    public override void Open()
    {
        SaslPlain plain = new SaslPlain("hive", "hive");
        // plain.GetResponse(
        byte[] initilaResponse = null;
        if (plain.HasInitial)
        {            initilaResponse = plain.GetResponse(new byte[0]);
        }

        Byte[] machinism = GetBytes("NONE");        messageHeader[0] = START;        encodeBigEndian(machinism.Length, messageHeader, 1);        underlyingTransport.Open();        underlyingTransport.Write(messageHeader);        underlyingTransport.Write(machinism);        underlyingTransport.Flush();

        Byte by = plain.IsCompleted ? COMPLETE : OK;        messageHeader[0] = by;        encodeBigEndian(initilaResponse.Length, messageHeader, 1);        underlyingTransport.Write(messageHeader);        underlyingTransport.Write(initilaResponse);        underlyingTransport.Flush();        underlyingTransport.Flush();


    }
    }

    public override void Close()
    {        underlyingTransport.Close();
    }

    public override int Read(byte[] buf, int off, int len)
    {
        return underlyingTransport.Read(buf, off, len);
    }

    public override void Write(byte[] buf, int off, int len)
    {        underlyingTransport.Write(buf, off, len);
    }

    protected override void Dispose(bool disposing)
    {        underlyingTransport.Dispose();
    }


    static byte[] GetBytes(string str)
    {
        return Encoding.UTF8.GetBytes(str);
    }

    public static void encodeBigEndian(int integer, byte[] buf, int offset)
    {        buf[offset] = (byte)(0xff & (integer >> 24));        buf[offset + 1] = (byte)(0xff & (integer >> 16));        buf[offset + 2] = (byte)(0xff & (integer >> 8));        buf[offset + 3] = (byte)(0xff & (integer));
    }

    public static int decodeBigEndian(byte[] buf, int offset)
    {
        return ((buf[offset] & 0xff) << 24) | ((buf[offset + 1] & 0xff) << 16)
            | ((buf[offset + 2] & 0xff) << 8) | ((buf[offset + 3] & 0xff));
    }

    protected static int DEFAULT_MAX_LENGTH = 0x7FFFFFFF;

    protected static int MECHANISM_NAME_BYTES = 1;
    protected static int STATUS_BYTES = 1;
    protected static int PAYLOAD_LENGTH_BYTES = 4;

    protected enum SaslRole
    {        SERVER, CLIENT
    }
Don't have an account?
Coming from Hortonworks? Activate your account here