lenchv / hive-driver

Driver for connection to Apache Hive via Thrift API
MIT License
40 stars 9 forks source link

Required field 'client_protocol' is unset! #23

Closed jiaotashidi closed 4 years ago

jiaotashidi commented 4 years ago
const hive = require('../');
const { TCLIService, TCLIService_types } = hive.thrift;
const client = new hive.HiveClient(
    TCLIService,
    TCLIService_types
);

client.connect(
    {
        host: '10.101.3.14',
        port: 10000,
        // options: {
        //     username: '11104552',
        //     password: 'iy9xy4'
        // }
    },
    new hive.connections.TcpConnection(),
    // new hive.auth.NoSaslAuthentication()
    new hive.auth.PlainTcpAuthentication({
        username: '11104552',
        password: 'iy9xy4'
    })
).then( async client => {
    const session = await client.openSession({
        client_protocol: TCLIService_types.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V10
    });
    console.log(session)
    const response = await session.getInfo(
        TCLIService_types.TGetInfoType.CLI_DBMS_VER
    );
    console.log(response)
    console.log(response.getValue());

    await session.close();
}).catch(error => {
    console.log(error);
});

error message:

{ TApplicationException: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null)
    at exports.Client.TCLIServiceClient.recv_OpenSession (d:\My Documents\Desktop\hive-driver-master\thrift\gen-nodejs\TCLIService.js:2417:13)
    at d:\My Documents\Desktop\hive-driver-master\node_modules\thrift\lib\nodejs\lib\thrift\connection.js:143:41
    at Socket.<anonymous> (d:\My Documents\Desktop\hive-driver-master\node_modules\thrift\lib\nodejs\lib\thrift\framed_transport.js:60:7)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at Socket.Readable.push (_stream_readable.js:219:10)
    at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
  name: 'TApplicationException',
  message:
   'Required field \'client_protocol\' is unset! Struct:TOpenSessionReq(client_protocol:null)',
  type: 7 }
lenchv commented 4 years ago

Hi @jiaotashidi , can you approve that you compiled another TCLIService.thrift that provided by library? Can you check that value exists TCLIService_types.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V10? If not, you should check at thrift/gen-nodejs/TCLIService_types.js what the API supports and decrease version.

Let me know if this fixed your issue.

jiaotashidi commented 4 years ago
const hive = require('../');
const { TCLIService, TCLIService_types } = hive.thrift;

console.log(TCLIService_types.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V10)

const client = new hive.HiveClient(
    TCLIService,
    TCLIService_types
);

client.connect(
    {
        host: '10.101.3.14',
        port: 10000,
        // options: {
        //     username: '11104552',
        //     password: 'iy9xy4'
        // }
    },
    new hive.connections.TcpConnection(),
    // new hive.auth.NoSaslAuthentication()
    new hive.auth.PlainTcpAuthentication({
        username: '11104552',
        password: 'iy9xy4'
    })
).then( async client => {
    const session = await client.openSession({
        client_protocol: TCLIService_types.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V10
    });
    console.log(session)
    const response = await session.getInfo(
        TCLIService_types.TGetInfoType.CLI_DBMS_VER
    );
    console.log(response)
    console.log(response.getValue());

    await session.close();
}).catch(error => {
    console.log(error);
});

the console.log can output 9

d:\My Documents\Desktop\hive-driver-master>node examples/usage.js
9
{ TApplicationException: Required field 'client_protocol' is unset! Struct:TOpenSessionReq(client_protocol:null)
    at exports.Client.TCLIServiceClient.recv_OpenSession (d:\My Documents\Desktop\hive-driver-master\thrift\gen-nodejs\TCLIService.js:2417:13)
    at d:\My Documents\Desktop\hive-driver-master\node_modules\thrift\lib\nodejs\lib\thrift\connection.js:143:41
    at Socket.<anonymous> (d:\My Documents\Desktop\hive-driver-master\node_modules\thrift\lib\nodejs\lib\thrift\framed_transport.js:60:7)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at Socket.Readable.push (_stream_readable.js:219:10)
    at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
  name: 'TApplicationException',
  message:
   'Required field \'client_protocol\' is unset! Struct:TOpenSessionReq(client_protocol:null)',
  type: 7 }
jiaotashidi commented 4 years ago

the TCLIService_types.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V10 value is 9

lenchv commented 4 years ago

I see now, it is a response from the server. You should decrease the version of API until you manage to connect. It depends on the Hive version you use, I know that for version <2.1 the version has to be: TCLIService_types.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8

jiaotashidi commented 4 years ago

yes, the hive server version is 1.1

lenchv commented 4 years ago

@jiaotashidi can you tell please what protocol version of API is fit to hive server 1.1?

jiaotashidi commented 4 years ago
const hive = require('../dist');
const { TCLIService, TCLIService_types } = hive.thrift;
const client = new hive.HiveClient(
    TCLIService,
    TCLIService_types
);
const utils = new hive.HiveUtils(
    TCLIService_types
);
client.connect(
    {
        host: '10.101.3.14',
        port: 10000
    },
    new hive.connections.TcpConnection(),
    new hive.auth.PlainTcpAuthentication({
        username: '11104552',
        password: 'iy9xy4'
    })
)
.then(async client => {
    console.log('++++++++++++++++++++++++')
    const session = await client.openSession({
        client_protocol: TCLIService_types.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V1
    });
    const selectDataOperation = await session.executeStatement(
        `select * from cpd_reco.dm_recommend_algo_cvr_index_copy where day='2020-03-27'`, { runAsync: true }
    );
    await utils.waitUntilReady(selectDataOperation, false, () => {});
    await utils.fetchAll(selectDataOperation);
    await selectDataOperation.close();

    const result = utils.getResult(selectDataOperation).getValue();

    console.log(JSON.stringify(result, null, '\t'));

    await session.close();
    await client.close();
})
.catch(error => {
    console.error(error);
});

get getResult happen error

TypeError: Cannot read property 'binaryVal' of undefined
    at JsonResult.getColumnValue (d:\My Documents\Desktop\hive-driver-master\dist\result\JsonResult.js:113:22)
    at JsonResult.getSchemaValues (d:\My Documents\Desktop\hive-driver-master\dist\result\JsonResult.js:56:32)
    at d:\My Documents\Desktop\hive-driver-master\dist\result\JsonResult.js:42:26
    at Array.reduce (<anonymous>)
    at JsonResult.getRows (d:\My Documents\Desktop\hive-driver-master\dist\result\JsonResult.js:41:28)
    at d:\My Documents\Desktop\hive-driver-master\dist\result\JsonResult.js:29:30
    at Array.reduce (<anonymous>)
    at JsonResult.getValue (d:\My Documents\Desktop\hive-driver-master\dist\result\JsonResult.js:27:26)
    at client.connect.then (d:\My Documents\Desktop\hive-driver-master\examples\usage.js:45:57)
    at process._tickCallback (internal/process/next_tick.js:68:7)
ntallapa12 commented 4 years ago

I am using V7 for 1.1

lenchv commented 4 years ago

It is interesting, I face the same error, probably V1 API had another structure for the response.

@jiaotashidi can you try V7, as @ntallapa12 suggested, and tell if it works?

jiaotashidi commented 4 years ago

v7 is work , thank you very much