Loading and Fetching the Data using Node js.

classic Classic list List threaded Threaded
4 messages Options
nithin91 nithin91
Reply | Threaded
Open this post in threaded view
|

Loading and Fetching the Data using Node js.

Hi

I am new to Apache Ignite.Can someone help me on how to fetch and load the
data from ignite cache
using node js without using sql field queries option. Cache is loaded using
CacheJDBCPOJO Store and the Key and Value types are custom types defined
using JAVA.As these classes are defined in Java not sure on how to fetch the
data using node.

Hope the following example , explains the issue better.

We have ignite cache of custom key Type i.e Person Key with attributes
Person First Name and person Last Name and custom value type  i.e Person
Info with attributes Person Address and Person Age etc.
 These classes are defined in Java and the caches are configured in Bean
File and loaded using CacheJDBCPOJO Store.

As these classes will not be available in node js, how can we load /fetch
the data from node js using cahe.put /cache.get.Tried creating similar
classes in node and pass the object of these classes to
cahe.put /cache.get but it is in't working.





--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
dmagda dmagda
Reply | Threaded
Open this post in threaded view
|

Re: Loading and Fetching the Data using Node js.

Hello,

Have you tried to create Node.JS classes with a structure similar to Java objects and use them in put/get methods? 

As for the initial data loading, an efficient API has not been added to the Node.JS yet. Use Java IgniteDataStreamer or CacheStore.load to load records to Ignite.

-
Denis


On Tue, Feb 11, 2020 at 11:50 PM nithin91 <[hidden email]> wrote:
Hi

I am new to Apache Ignite.Can someone help me on how to fetch and load the
data from ignite cache
using node js without using sql field queries option. Cache is loaded using
CacheJDBCPOJO Store and the Key and Value types are custom types defined
using JAVA.As these classes are defined in Java not sure on how to fetch the
data using node.

Hope the following example , explains the issue better.

We have ignite cache of custom key Type i.e Person Key with attributes
Person First Name and person Last Name and custom value type  i.e Person
Info with attributes Person Address and Person Age etc.
 These classes are defined in Java and the caches are configured in Bean
File and loaded using CacheJDBCPOJO Store.

As these classes will not be available in node js, how can we load /fetch
the data from node js using cahe.put /cache.get.Tried creating similar
classes in node and pass the object of these classes to
cahe.put /cache.get but it is in't working.





--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
nithin91 nithin91
Reply | Threaded
Open this post in threaded view
|

Re: Loading and Fetching the Data using Node js.

Hi

Pasted below the code and error i got.Actually i am trying query an existing
cache using node js which is loaded using Cache JDBC Pojo Store in Java.It
would be really helpful share me if you have any sample code.

PS C:\Users\ngovind\NodeApp> node NodeIgnite.js
ERROR: Binary type has different field types [typeName=OrderId,
fieldName=OrderID, fieldTypeName1=long, fieldTypeName2=double]
(node:13596) UnhandledPromiseRejectionWarning: ReferenceError: igniteClient
is not defined
    at start (C:\Users\ngovind\NodeApp\NodeIgnite.js:44:5)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:13596) UnhandledPromiseRejectionWarning: Unhandled promise rejection.
This error originated either by throwing inside of an async function without
a catch block, or by rejecting a promise which was not handled with
.catch(). (rejection id: 1)
(node:13596) [DEP0018] DeprecationWarning: Unhandled promise rejections are
deprecated. In the future, promise rejections
that are not handled will terminate the Node.js process with a non-zero exit
code.




const IgniteClient = require('apache-ignite-client');
const IgniteClientConfiguration = IgniteClient.IgniteClientConfiguration;
const ObjectType = IgniteClient.ObjectType;
const CacheEntry = IgniteClient.CacheEntry;
const ComplexObjectType = IgniteClient.ComplexObjectType;

class OrderKey {
    constructor(OrderID = null, CityID= null) {
        this.OrderID = OrderID;
        this.CityID = CityID;
    }  
}

class OrderDetails {
    constructor(Productname = null, CustomerName= null,StoreName=null) {
        this.Productname = Productname;
        this.CustomerName = CustomerName;
        this.StoreName = StoreName;
    }  
}

async function start(){
try {
    const igniteClient = new IgniteClient();
    await igniteClient.connect(new
IgniteClientConfiguration('127.0.0.1:10800'));
    const cache = await igniteClient.getCache('OrdersCache');
    const OrderKeyComplexObjectType =
    new ComplexObjectType(new OrderKey(0,0),'OrderId');
    const OrderComplexObjectType = new ComplexObjectType(new
OrderDetails('','',''),'Orders')
    ;

   cache.setKeyType(OrderKeyComplexObjectType).
   setValueType(OrderComplexObjectType);

    const data = await cache.get(new OrderKey(1,1));
   console.log(data.Productname);

}
catch (err) {
    console.log('ERROR: ' + err.message);
}
finally {

    igniteClient.disconnect();
     
    console.log(" Data Fetch Completed");

}
}

start();



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
dmagda dmagda
Reply | Threaded
Open this post in threaded view
|

Re: Loading and Fetching the Data using Node js.

According to the exception, the field name OrderId is of "long" type in Java and of "double" type in Node.JS (or vice versa). The types of the fields have to be identical. It seems like OrderId is a primitive field and you, probably, should enforce its type to "long" on Node.JS end.

Also, check this example that shows how to enforce specific field types from Node.JS to ensure they match the types of Java counterparts:

If nothing works, please share a GitHub project with Java POJOs and anything else that will help to get to the bottom of this.


-
Denis


On Thu, Feb 13, 2020 at 1:49 AM nithin91 <[hidden email]> wrote:
Hi

Pasted below the code and error i got.Actually i am trying query an existing
cache using node js which is loaded using Cache JDBC Pojo Store in Java.It
would be really helpful share me if you have any sample code.

PS C:\Users\ngovind\NodeApp> node NodeIgnite.js
ERROR: Binary type has different field types [typeName=OrderId,
fieldName=OrderID, fieldTypeName1=long, fieldTypeName2=double]
(node:13596) UnhandledPromiseRejectionWarning: ReferenceError: igniteClient
is not defined
    at start (C:\Users\ngovind\NodeApp\NodeIgnite.js:44:5)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:13596) UnhandledPromiseRejectionWarning: Unhandled promise rejection.
This error originated either by throwing inside of an async function without
a catch block, or by rejecting a promise which was not handled with
.catch(). (rejection id: 1)
(node:13596) [DEP0018] DeprecationWarning: Unhandled promise rejections are
deprecated. In the future, promise rejections
that are not handled will terminate the Node.js process with a non-zero exit
code.




const IgniteClient = require('apache-ignite-client');
const IgniteClientConfiguration = IgniteClient.IgniteClientConfiguration;
const ObjectType = IgniteClient.ObjectType;
const CacheEntry = IgniteClient.CacheEntry;
const ComplexObjectType = IgniteClient.ComplexObjectType;

class OrderKey {
    constructor(OrderID = null, CityID= null) {
        this.OrderID = OrderID;
        this.CityID = CityID;
    } 
}

class OrderDetails {
    constructor(Productname = null, CustomerName= null,StoreName=null) {
        this.Productname = Productname;
        this.CustomerName = CustomerName;
        this.StoreName = StoreName;
    } 
}

async function start(){
try {
    const igniteClient = new IgniteClient();
    await igniteClient.connect(new
IgniteClientConfiguration('127.0.0.1:10800'));
    const cache = await igniteClient.getCache('OrdersCache');
    const OrderKeyComplexObjectType =
    new ComplexObjectType(new OrderKey(0,0),'OrderId');
    const OrderComplexObjectType = new ComplexObjectType(new
OrderDetails('','',''),'Orders')
    ;

   cache.setKeyType(OrderKeyComplexObjectType).
   setValueType(OrderComplexObjectType);

    const data = await cache.get(new OrderKey(1,1));
   console.log(data.Productname);

}
catch (err) {
    console.log('ERROR: ' + err.message);
}
finally {

    igniteClient.disconnect();

    console.log(" Data Fetch Completed");

}
}

start();



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/