Creating hierarchical menu in asp.net using SQL - asp.net

I'm trying to use to create a hierarchical menu from a SQL data source in asp.net. I'm having trouble ordering my table so that I can easily create the menu in asp.net. There may be a better way to do it if anyone has any ideas...
I currently have a table that looks like this (made up sample data), there are only folders at the root and only folders can have folder Ids:
+-------------------+---------------------+-----------+-----------+
| Name_FolderorItem | Parent_Folder | Id_Folder | Menuplace |
+-------------------+---------------------+-----------+-----------+
| c FOLDER | ROOT | c_FOLDER | 1 |
| d FOLDER | j_FOLDER | d_FOLDER | 2 |
| a FOLDER | ROOT | a_FOLDER | 1 |
| j FOLDER | ROOT | j_FOLDER | 1 |
| f FOLDER | ROOT | f_FOLDER | 1 |
| r FOLDER | f_FOLDER | r_FOLDER | 2 |
| i FOLDER | d_FOLDER | i_FOLDER | 3 |
| a ITEM | j_FOLDER | | 2 |
| d ITEM | c_FOLDER | | 2 |
| z ITEM | f_FOLDER | | 2 |
| r ITEM | d_FOLDER | | 3 |
+-------------------+---------------------+-----------+-----------+
I'm thinking that If I order it to get this which is alphabetical on the first level then alphabetical on each deeper level:
+-------------------+---------------------+-----------+-----------+
| Name_FolderorItem | Parent_Folder | Id_Folder | Menuplace |
+-------------------+---------------------+-----------+-----------+
| a FOLDER | ROOT | a_FOLDER | 1 |
| c FOLDER | ROOT | c_FOLDER | 1 |
| d ITEM | c_FOLDER | | 2 |
| f FOLDER | ROOT | f_FOLDER | 1 |
| r FOLDER | f_FOLDER | r_FOLDER | 2 |
| z ITEM | f_FOLDER | | 2 |
| j FOLDER | ROOT | j_FOLDER | 1 |
| a ITEM | j_FOLDER | | 2 |
| d FOLDER | j_FOLDER | d_FOLDER | 2 |
| i FOLDER | d_FOLDER | i_FOLDER | 3 |
| r ITEM | d_FOLDER | | 3 |
+-------------------+---------------------+-----------+-----------+
Then I can use a listview to get this menu structure:
a FOLDER
c FOLDER
- d ITEM
f FOLDER
- r FOLDER (r FOLDER is located in f folder)
- z ITEM
j FOLDER
- a item
- d FOLDER
- - i FOLDER
- - r ITEM
I can't seem to figure out the required SQL to take a folder and then prioritise what is inside of it instead of the other folders/items on that level.
If you have any ideas on the SQL statements that would allow for this ordering I would appreciate it, thanks in advance
EDIT:
Here is the Query that I'm now using, thanks for the help
SELECT *
FROM table
START WITH Parent_Folder LIKE 'ROOT'
CONNECT BY PRIOR Id_Folder LIKE Parent_folder;

This is basically the problem of storing an ordered tree in a database. I have tried a few approaches in the past and would recommend this one:
-----------------------------------
| NodeID | ParentID | Order |
-----------------------------------
| 1 | -1 | 1 |
| 2 | 1 | 1 |
| 3 | 1 | 2 |
| 4 | 3 | 1 |
-----------------------------------
The GIST is each row corresponds to a node in the tree (or a menu item in your case), and it has a parentID that points to the parent. The root node either has null or -1 has its parentID since it does not have one. Now, to get all the nodes that are directly under the root, you'd use
SELECT * FROM table WHERE ParentID = -1 ORDER BY [Order]
[Order] tells you how to order the nodes in a directly under a specific parent node. (OK, it's not so good to name a column using a SQL keyword, but let's forget that for the moment). So in my example you can see both "2" and "3" are under the root, but "2" comes first. To select the nodes directly under "3" (its children in other words), you'd use
SELECT * FROM table WHERE ParentID = 3 ORDER BY [Order]
The advantage of this approach is it's easy to query the menu. The disadvantage is when you update, you have to make sure nodes that share the same ParentID (in other words under the same parent) do not share the name [Order].
Alternative approach
An alternative approach is to store the tree as something like a link list:
-----------------------------------
|NodeID | ParentID | PrevID | (optionally you can store NextID as well)
-----------------------------------
| 1 | -1 | -1 |
| 2 | 1 | -1 |
| 3 | 1 | 2 |
| 4 | 3 | -1 |
-----------------------------------
If your tree is very large and you need to quickly browse the sibling nodes, this approach would offer a better performance.

Related

Get memory, cpu and disk usage for each tenant in Openstack

I am looking for the CPU, Memory and Disk consumption for each Tenant in Openstack,and their relationship by users, instances, flavors in use. Horizon only shows utilization of memory, cpu of a global way. Is it possible to get it with Openstack commands?
My openstack is based on Rocky.
Any ideas will be really appreciated
The only thing I know is
openstack limits show --absolute --project <Project_ID/Tenant_ID>
see also https://docs.openstack.org/python-openstackclient/pike/cli/command-objects/limits.html
In the output you have information like for example totalCoresUsed, which represents the number of cores, which are used by the selected project.
Example:
root#openstack-controller:~# openstack limits show --absolute --project 416f937f505f4ff6b623c48a61228a86
+--------------------------+-------+
| Name | Value |
+--------------------------+-------+
| maxTotalInstances | 10 |
| maxTotalCores | 20 |
| maxTotalRAMSize | 51200 |
| maxSecurityGroups | 10 |
| maxTotalFloatingIps | 10 |
| maxServerMeta | 128 |
| maxImageMeta | 128 |
| maxPersonality | 5 |
| maxPersonalitySize | 10240 |
| maxSecurityGroupRules | 20 |
| maxTotalKeypairs | 100 |
| maxServerGroups | 10 |
| maxServerGroupMembers | 10 |
| totalRAMUsed | 2560 |
| totalCoresUsed | 7 |
| totalInstancesUsed | 7 |
| totalFloatingIpsUsed | 0 |
| totalSecurityGroupsUsed | 1 |
| totalServerGroupsUsed | 0 |
| maxTotalVolumes | 10 |
| maxTotalSnapshots | 10 |
| maxTotalVolumeGigabytes | 1000 |
| maxTotalBackups | 10 |
| maxTotalBackupGigabytes | 1000 |
| totalVolumesUsed | 5 |
| totalGigabytesUsed | 7 |
| totalSnapshotsUsed | 0 |
| totalBackupsUsed | 0 |
| totalBackupGigabytesUsed | 0 |
+--------------------------+-------+
The quotas and so the limitations are bind to projects and not to users, so I don't know if it is possible to get a relationshit by users. The only idea I would have, would a simple bash-script, which iterates over all instances and volumes of a project and collect the information of each ressource by the user, who created it.
Update 30.7.2020:
Found a better solution now, which also allows to get the resource usage per user of a project. It comes with the new placement-component with the stein-release of openstack (tested in train-release of openstack).
Installation of the openstack-client extension: pip install osc-placement
Ressource-usage of a project:
openstack resource usage show --os-placement-api-version 1.9 <PROJECT_ID>
Ressource-usage of a specific user within a project:
openstack resource usage show --os-placement-api-version 1.9 --user-id <USER_ID> <PROJECT_ID>
Example:
openstack resource usage show --os-placement-api-version 1.9 --user-id 98378bd3cdd94218bf7b6ef4ec80e74a 7733616a513444c2a106243db318b0dd
+----------------+-------+
| resource_class | usage |
+----------------+-------+
| VCPU | 3 |
| MEMORY_MB | 768 |
| DISK_GB | 9 |
+----------------+-------+

Is there a way to show partitions on Cloudera impala?

Normally, I can do show partitions <table> in hive. But when it is a parquet table, hive does not understand it. I can go to hdfs and check the dir structure, but that is not ideal. Is there any better way to do that?
I am using Impala 1.4.0 and I can see partitions.
From the impala-shell give the command:
show partitions <mytablename>
I have something looking like this:
+-------+-------+-----+-------+--------+---------+--------------+---------+
| year | month | day | #Rows | #Files | Size | Bytes Cached | Format |
+-------+-------+-----+-------+--------+---------+--------------+---------+
| 2013 | 11 | 1 | -1 | 3 | 25.87MB | NOT CACHED | PARQUET |
| 2013 | 11 | 2 | -1 | 3 | 24.84MB | NOT CACHED | PARQUET |
| 2013 | 11 | 3 | -1 | 2 | 19.05MB | NOT CACHED | PARQUET |
| 2013 | 11 | 4 | -1 | 3 | 23.63MB | NOT CACHED | PARQUET |
| 2013 | 11 | 5 | -1 | 3 | 26.56MB | NOT CACHED | PARQUET |
Alternatively you can go to your table in HDFS . They are normally seen in this path:
/user/hivestore/warehouse/<mytablename> or
/user/hive/warehouse/<mytablename>
Unfortunately no. Issue is open though. So checking it manually seems to be the only option right now.

Select single row per unique field value with SQL Developer

I have thousands of rows of data, a segment of which looks like:
+-------------+-----------+-------+
| Customer ID | Company | Sales |
+-------------+-----------+-------+
| 45678293 | Sears | 45 |
| 01928573 | Walmart | 6 |
| 29385068 | Fortinoes | 2 |
| 49582015 | Walmart | 1 |
| 49582015 | Joe's | 1 |
| 19285740 | Target | 56 |
| 39506783 | Target | 4 |
| 39506783 | H&M | 4 |
+-------------+-----------+-------+
In every case that a customer ID occurs more than once, the value in 'Sales' is also the same but the value in 'Company' is different (this is true throughout the entire table). I need for each value in 'Customer ID to only appear once, so I need a single row for each customer ID.
In other words, I'd like for the above table to look like:
+-------------+-----------+-------+
| Customer ID | Company | Sales |
+-------------+-----------+-------+
| 45678293 | Sears | 45 |
| 01928573 | Walmart | 6 |
| 29385068 | Fortinoes | 2 |
| 49582015 | Walmart | 1 |
| 19285740 | Target | 56 |
| 39506783 | Target | 4 |
+-------------+-----------+-------+
If anyone knows how I can go about doing this, I'd much appreciate some help.
Thanks!
Well it would have been helpful, if you have put your sql generate that data.
but it might go something like;
SELECT customer_id, Max(Company) as company, Count(sales.*) From Customers <your joins and where clause> GROUP BY customer_id
Assumes; there are many company and picks out the most number of occurance and the sales data to be in a different table.
Hope this helps.

Incrementing an ID number each time a condition is met

I have a dataset that I'm trying to chunk up into "events" based on a condition. I want to create a consecutive group number (ID) which increases each time the condition is met.
Some kinds of records indicate that a new event has started, while other kinds of records represent no change / staying the course.
For example, in this dataset whenever 'Action' is "Left" or "Right", a new event has started and 'Id' should be incremented by 1:
| Id | Action |
|-----+---------|
| 1 | Left |
| 2 | Forward |
| 3 | Forward |
| 4 | Right |
| 5 | Forward |
| 6 | Left |
| ... | ... |
The resulting table I want would look like:
| Id | Action | GroupId |
|-----+---------+---------|
| 1 | Left | 1 |
| 2 | Forward | 1 |
| 3 | Forward | 1 |
| 4 | Right | 2 |
| 5 | Forward | 2 |
| 6 | Left | 3 |
| ... | ... | ... |
In something like python I might do this with a counter and a for loop (pseudo-ish code):
GroupID = 1
for row in data:
if Action == "Left" OR Action == "Right":
GroupID = GroupID + 1
else:
GroupID = GroupID
I feel like this should be a really simple one-liner, but my brain is broken right now and I'm having a hard time conceptualizing this.
GroupId = cumsum(Action %in% c("Left", "Right"))

delete whole row of gridview

how can i delete the whole rows of gridview using code behind c sharp like
+-----+-----+------+
|Col1 | Col2| Col3 |
| | | |
| a | 1 | 5 |
| | | |
| a | 2 | 6 |
| | | |
| a | 3 | 7 |
| | | |
| a | 4 | 8 |
+-----+-----+------+
and I want to delete the whole rows in the gridview so that it becomes
+-----+-----+------+
|Col1 | Col2| Col3 |
| | | |
| a | 4 | 8 |
+-----+-----+------+
only last duplicate row left and all the rest is deleted (rows are deleted from all the columns of gridview)
Anyone knows how to achieve this?
Have a look at GridView.DeleteRow(). MSDN documentation is here: GridView.DeleteRow Method

Resources