How to use data compression

Answered
KonektDev asked on November 5, 2018

Hi 
I would like to use the data compression. We are using Sql server, web Api in .Net and Angular 6, The examples I have seen use a SqlDataReader and then compress the output of the SqlDataReader but we need to add data types and from the examples I haven't seen anywhere where the data is compressed and the data types have been included.
I have attached an example of the data with the data types here in JSON format. Is it possible to use the compressor with the JSON data? Or is there another approach t use? Would you please provide a code example? 
Thanks

Attachments:
jsondata.txt

7 answers

Public
Dmytro Zvazhii Dmytro Zvazhii Flexmonster November 6, 2018

Hello,
Thank you for your questions.
Flexmonster Data Compressor for the .Net works with the CSV data format. Currently, it does not support JSON data as input. You can see more information about our Data Compressor here: https://www.flexmonster.com/doc/connecting-to-relational-database-with-net/. Please note, that you can connect directly to the SQL database without any data conversion. The data types for the CSV data source can be specified in the following way: https://www.flexmonster.com/doc/managing-data-presentation-csv/.
 
In case you prefer using JSON data type we can suggest you Flexmonster Data Compressor for the Node.js: https://www.flexmonster.com/doc/connecting-to-database-with-node-js/. It supports both JSON and CSV data formats.
 
We have checked your JSON data example and the data types are specified correctly. Also, you can always refer to the following article about JSON data types: https://www.flexmonster.com/doc/managing-data-presentation-json.
Could you please specify your data storage technology? It would be much easier for us to find a suitable solution for you.
 
Let us know if you need any other assistance.
Regards,
Dmytro

Public
KonektDev November 12, 2018

Hi,
 
We are using SQL backend and using a SQL function to retrieve the data. Once the API has the data, we run this code below to add the data types and to add myPrimaryKey column which we need at the angular side to have a key per record. We also add date/double etc data types so the values display correctly on the UI.
 
We can't find out how to use the compressor and run this code below at the same time. Compressor takes the DBreader but we want to compress the data after we add our custom data types.

 
for (var i = 0; i < reader.FieldCount; i++)
			{
				cols.Add(reader.GetName(i));
				sqlDataTypes.Add(reader.GetFieldType(i));
				if (reader.GetName(i) == "ID")
				{
					flexMonsterDataTypes.Add("myPrimaryKey", new CaseListDataTypeDto { Type = "id" });
				}
 
				if (reader.GetFieldType(i) == typeof(DateTime))
				{
					flexMonsterDataTypes.Add(reader.GetName(i), new CaseListDataTypeDto { Type = "date string" });
				}
				else if (reader.GetFieldType(i) == typeof(int) ||
						reader.GetFieldType(i) == typeof(double))
				{
					flexMonsterDataTypes.Add(reader.GetName(i), new CaseListDataTypeDto { Type = "number" });
				}
				else if (reader.GetFieldType(i) == typeof(string))
				{
					flexMonsterDataTypes.Add(reader.GetName(i), new CaseListDataTypeDto { Type = "string" });
				}
				else
				{
					var test = reader.GetFieldType(i);
				}
			}
Public
Dmytro Zvazhii Dmytro Zvazhii Flexmonster November 12, 2018

Hi,
Thank you for providing specific details. We can suggest you the following approach: 

  • composing the data into CSV according to your additional requirements
  • stream the composed data to the compressor
  • you can use CompressStream(Stream stream, char delimiter) method
  • in such case, you can compose and stream data on the run

Does the suggested approach work for you?
Please let us know if you need more guidance from us?
Regards,
Dmytro

Public
KonektDev November 13, 2018

We would like to stay away from CSV. The code we sent you above, is it possible to run that code on the angular side after the data is decompressed? So we can compress the data without CSV, send it to the client and add "myPrimaryKey" and other data types on the angular side after the data has been decompressed?

Public
Tanya Gryshko Tanya Gryshko Flexmonster November 15, 2018

Hello,
Thank you for your reply.
First of all, we would like to mention that it is possible to add some data types on the server-side via SQL query alias. For example, to set Month data type, you can use the following syntax:

"SELECT month as 'm+Month' FROM customers"

The list of all data types is available here (please note, in this case, you can compress the data without CSV). Let me know if this approach works for you.
As about some additional data processing on the client side, the process of data decompression happens inside Flexmonster. That is why it is not possible to add changes to the decompressed data. However, you can modify the compressed data, if needed.
Please let me know in case of additional questions.
Regards,
Tanya

Public
KonektDev November 16, 2018

Hi Tanya, Dmytro,
We tried using the csv data compressor. The webapi successfully returns the compressed data. I have added a screen shot of the code and the returned data. However despite the typescript code calling the webapi and the data being returned to the client, the data does not load. The "Loading data" message and the spinning icon are displayed and do not go away. I have also attached screen shots of the html and the typescript code. Would you please give me an idea where we are going wrong 
We are calling the web api from the PivotReady function. Is this correct?
 

Public
Tanya Gryshko Tanya Gryshko Flexmonster November 16, 2018

Hello,
Thank you for a quick update.
First of all, on the client side, your code seems to be correct. However, the format of compressed-csv-data.txt differs from typical OCSV format. Please have a look at the usual format: http://olap.flexmonster.com/compressor/demo.php.
Your OCSV should look the same. After that, if the "Loading data" message still appears, please open the browser console and check for errors. Sharing with us the screenshots of the errors would greatly help us.
Waiting for your feedback.
Regards,
Tanya

Please login or Register to Submit Answer