Hello again!

A tiny addendum - you can mark key fields with QueryField.IsKeyField and
forget what I have said about XML and stuff.

Regards,
-- 
Ilya Kasnacheev


вт, 19 нояб. 2019 г. в 19:36, Ilya Kasnacheev <ilya.kasnach...@gmail.com>:

> Hello!
>
> Your code is mostly sound, but there are a few issues of understanding.
>
> Please see my replies inline.
>
> пт, 15 нояб. 2019 г. в 22:43, Manan Joshi <manan.jo...@izenda.com>:
>
>>  public void CreateCache(string connectionString, string schema, string
>> table, Dictionary<string, Type> fields, string[] keys)
>>         {
>>             string query = String.Format("{0} {1}.{2}", "SELECT * FROM",
>> schema, table);
>>             string cachename = CacheNameHash(connectionString, schema,
>> table);
>>             if (_dataSourceAdaptor.TestConnection(_serverType,
>> connectionString).Status == Framework.Constants.ConnectDBStatus.Success)
>>             {
>>                 var result = 
>> _dataSourceAdaptor.QueryMultiple<dynamic>(connectionString,
>> query,null,60 ,null).AsList();
>>                 var cacheConfiguration = new CacheConfiguration() {
>>                     Name = cachename, QueryEntities = new[] {
>>                     new QueryEntity { TableName = "Orders" ,
>> ValueTypeName="Orders" , KeyTypeName="Orders", Fields=   new[]
>>
> You should make sure that key type name != value type name to avoid
> confusion, make it OrdersKey perhaps ^?
> If your key is single-field it's best to use primitive type, specify
> KeyFieldName to give it a column name.
>
>                             {
>>                                 new QueryField("OrderID", typeof(int)),
>>                                 new QueryField("EmployeeID", typeof(int)),
>>                                 new QueryField("CustomerID", typeof(int)),
>>                             }, }
>>
> You should probably specify which ones of these reside in key and which in
> value by specifying keyFields. However, it seems that there is no way to
> specify them from .Net API :( this probably means you will have to use XML
> config or use primitive key or use annotations within key class (which you
> will need to create). Pavel, please correct me if I'm wrong.
> You can still use BinaryObject approach here instead of key class, which
> will be only used as reference.
>
>
>>
>>                 } };
>>                 var cache = ignite.GetOrCreateCache<IBinaryObject,
>> IBinaryObject>(cacheConfiguration).WithKeepBinary<IBinaryObject,
>> IBinaryObject>();
>>                 using (var streamer = ignite.GetDataStreamer<IBinaryObject,
>> IBinaryObject>(cache.Name))
>>                 {
>>                     foreach (var item in result)
>>                     {
>>                         var dataRow = (IDictionary<string, object>)item;
>>                         IBinaryObjectBuilder keyBuilder =
>> ignite.GetBinary().GetBuilder(table);
>>                         IBinaryObjectBuilder valueBuilder =
>> ignite.GetBinary().GetBuilder(table);
>>
> These should be "OrdersKey" / "Orders", and *not* table name. This is
> because type name is discriminator and mismatching it will cause data to be
> unavailable for SQL.
>
>                         SetBuiderFields(fields, keys, dataRow,table,out
>> keyBuilder);
>>                         SetBuiderFields(fields, new
>> List<string>(fields.Keys).ToArray(), dataRow, table, out valueBuilder);
>>
>                         streamer.AddData(keyBuilder.
>> Build(),valueBuilder.Build());
>>                     }
>>                 }
>>                 var queryreults = cache.Query(new SqlFieldsQuery("select
>> OrderID from Orders"));
>>
> After those fixes, the code worked for me, provided some results.
>
> Regards,
> --
> Ilya Kasnacheev
>
>
>>
>> On Fri, Nov 15, 2019 at 2:41 PM Pavel Tupitsyn <ptupit...@apache.org>
>> wrote:
>>
>>> Can you please attach full code as text? Can't run a screenshot :)
>>>
>>> On Fri, Nov 15, 2019 at 10:35 PM Manan Joshi <manan.jo...@izenda.com>
>>> wrote:
>>>
>>>> Some more help :)
>>>>
>>>>
>>>> [image: image.png]
>>>>
>>>> I am seeing cache are stored fine in key and in value but when run the
>>>> query it throws exception on table not found. Can you help me out what i am
>>>> missing?
>>>>
>>>> On Fri, Nov 15, 2019 at 12:32 PM Pavel Tupitsyn <ptupit...@apache.org>
>>>> wrote:
>>>>
>>>>> Yes, you can use IBinaryObject as a key. Yes, SQL will work too.
>>>>>
>>>>> On Fri, Nov 15, 2019 at 7:51 PM Manan Joshi <manan.jo...@izenda.com>
>>>>> wrote:
>>>>>
>>>>>> Paval,
>>>>>>
>>>>>> Thanks you for response.
>>>>>>
>>>>>> I have trying to insert insert data using datastreamer into ignite ,
>>>>>> Can you tell me what is the best practice to creating key into ignite.
>>>>>>
>>>>>> if i want to create multiple columns of db as key should i use
>>>>>> Ibinaryobject to store as object ? will ignite sql engine understand the
>>>>>> indexes if key is in IBinaryObject.
>>>>>>
>>>>>> Thanks
>>>>>> Manan Joshi
>>>>>>
>>>>>> On Fri, Nov 15, 2019 at 11:00 AM Pavel Tupitsyn <ptupit...@apache.org>
>>>>>> wrote:
>>>>>>
>>>>>>> When using `dynamic` with Dapper, underlying objects are of type
>>>>>>> DapperRow, which is also IDictionary<string, object>,
>>>>>>> which is easy to convert to BinaryObject. Here is a full example
>>>>>>> with Dapper query:
>>>>>>>
>>>>>>> var dapperQuery = conn.Query("SELECT * FROM Persons");
>>>>>>> foreach (IDictionary<string, object> row in dapperQuery)
>>>>>>> {
>>>>>>>     var builder = ignite.GetBinary().GetBuilder("YourEntityNameHere");
>>>>>>>     foreach (var pair in row)
>>>>>>>     {
>>>>>>>         builder.SetField(pair.Key, pair.Value);
>>>>>>>     }
>>>>>>>
>>>>>>>     var binaryObject = builder.Build();
>>>>>>>     Console.WriteLine(binaryObject);
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> On Fri, Nov 15, 2019 at 5:20 PM Ilya Kasnacheev <
>>>>>>> ilya.kasnach...@gmail.com> wrote:
>>>>>>>
>>>>>>>> Hello!
>>>>>>>>
>>>>>>>> You can try using ignite.binary().ToBinary(obj).
>>>>>>>>
>>>>>>>> However, in your case, it makes sense to avoid the intermediate
>>>>>>>> object stage directly and produce BinaryObjects from input data using
>>>>>>>> builder.
>>>>>>>>
>>>>>>>> Regards,
>>>>>>>> --
>>>>>>>> Ilya Kasnacheev
>>>>>>>>
>>>>>>>>
>>>>>>>> пт, 15 нояб. 2019 г. в 17:15, Manan Joshi <manan.jo...@izenda.com>:
>>>>>>>>
>>>>>>>>> I am reading the data using dapper from the database i am not sure
>>>>>>>>> how to convert fromSystem.Collections.Generic.IEnumbrable<dynamic>
>>>>>>>>> to Apache.Ignite.Core.Binary.IBinaryObject.
>>>>>>>>>
>>>>>>>>> Thanks
>>>>>>>>> Manan Joshi
>>>>>>>>>
>>>>>>>>> On Fri, Nov 15, 2019 at 8:46 AM Alexandr Shapkin <
>>>>>>>>> lexw...@gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> You can also refer to the BinaryModeExample.cs
>>>>>>>>>> <https://github.com/apache/ignite/blob/master/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/BinaryModeExample.cs>
>>>>>>>>>> example and the docs [1]
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> [1] -
>>>>>>>>>> https://apacheignite-net.readme.io/docs/binary-mode#section-creating-binary-objects
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> *From: *Ilya Kasnacheev <ilya.kasnach...@gmail.com>
>>>>>>>>>> *Sent: *Friday, November 15, 2019 4:13 PM
>>>>>>>>>> *To: *user@ignite.apache.org
>>>>>>>>>> *Subject: *Re: Store objects as IBinaryobject in cadche
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Hello!
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> You can use BinaryObjectBuilder:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> https://apacheignite.readme.io/docs/binary-marshaller#section-modifying-binary-objects-using-binaryobjectbuilder
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> However, each variation of its composition is stored in schema
>>>>>>>>>> cache, which means you should not have too many of those.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> It is recommended to use Map to store all variable/non-essential
>>>>>>>>>> fields if you have a lot of them.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Regards,
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>>
>>>>>>>>>> Ilya Kasnacheev
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> пт, 15 нояб. 2019 г. в 16:08, Manan Joshi <manan.jo...@izenda.com
>>>>>>>>>> >:
>>>>>>>>>>
>>>>>>>>>> I would like to store any time of object into cache as
>>>>>>>>>> IBinaryobject, so i can store cache stored in loosely bind with 
>>>>>>>>>> object. I
>>>>>>>>>> am working with Ignite .Net. Can someone please suggest something.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> I need something like
>>>>>>>>>>
>>>>>>>>>> MyObject obj = new MyObject();
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>  obj.setFieldA("A");
>>>>>>>>>>
>>>>>>>>>>  obj.setFieldB(123);
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>  BinaryObject binaryObj = Ignition.ignite().binary().toBinary(obj);
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Thanks
>>>>>>>>>>
>>>>>>>>>> Manan Joshi
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>

Reply via email to