public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin][RM4633] Bad view in partitioned tables
3+ messages / 2 participants
[nested] [flat]

* [pgAdmin][RM4633] Bad view in partitioned tables
@ 2020-01-03 11:28 Akshay Joshi <[email protected]>
  2020-01-06 06:31 ` Re: [pgAdmin][RM4633] Bad view in partitioned tables Khushboo Vashi <[email protected]>
  0 siblings, 1 reply; 3+ messages in thread

From: Akshay Joshi @ 2020-01-03 11:28 UTC (permalink / raw)
  To: pgadmin-hackers

Hi Hackers

Attached is the patch to support the view part of the multilevel
partitions. Users can perform all the operations except creating the
partitions as a partitioned table. Users can create a partition table
separately and attach it as a partition of another partition table.

There are two problems mentioned in the RM. I have fixed the first one and
we won't fix the second problem as by design we decided to show Partitions
like Schema->Table->Partitions

Please review it.
-- 
*Thanks & Regards*
*Akshay Joshi*

*Sr. Software Architect*
*EnterpriseDB Software India Private Limited*
*Mobile: +91 976-788-8246*


Attachments:

  [application/octet-stream] RM_4633.patch (9.6K, 3-RM_4633.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/__init__.py
index 11180ad85..72dbb5d24 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/__init__.py
@@ -200,52 +200,27 @@ class PartitionsView(BaseTableView, DataTypeReader, VacuumSettings):
 
     })
 
-    def children(self, **kwargs):
-        """Build a list of treeview nodes from the child nodes."""
-
-        if 'sid' not in kwargs:
-            return precondition_required(
-                gettext('Required properties are missing.')
-            )
-
-        from pgadmin.utils.driver import get_driver
-        manager = get_driver(PG_DEFAULT_DRIVER).connection_manager(
-            sid=kwargs['sid']
-        )
-
-        did = None
-        if 'did' in kwargs:
-            did = kwargs['did']
-
-        conn = manager.connection(did=did)
-
-        if not conn.connected():
-            return precondition_required(
-                gettext(
-                    "Connection to the server has been lost."
-                )
-            )
-
+    def _get_children_nodes(self, manager, **kwargs):
         nodes = []
+        # treat partition table as normal table.
+        # replace tid with ptid and pop ptid from kwargs
+        if 'ptid' in kwargs:
+            ptid = kwargs.pop('ptid')
+            kwargs['tid'] = ptid
+
         for module in self.blueprint.submodules:
             if isinstance(module, PGChildModule):
                 if manager is not None and \
                         module.BackendSupported(manager, **kwargs):
-                    # treat partition table as normal table.
-                    # replace tid with ptid and pop ptid from kwargs
-                    if 'ptid' in kwargs:
-                        ptid = kwargs.pop('ptid')
-                        kwargs['tid'] = ptid
                     nodes.extend(module.get_nodes(**kwargs))
             else:
                 nodes.extend(module.get_nodes(**kwargs))
 
-        # Return sorted nodes based on label
-        return make_json_response(
-            data=sorted(
-                nodes, key=lambda c: c['label']
-            )
-        )
+        if manager is not None and \
+                self.blueprint.BackendSupported(manager, **kwargs):
+            nodes.extend(self.blueprint.get_nodes(**kwargs))
+
+        return nodes
 
     @BaseTableView.check_precondition
     def list(self, gid, sid, did, scid, tid):
@@ -295,7 +270,7 @@ class PartitionsView(BaseTableView, DataTypeReader, VacuumSettings):
         """
         SQL = render_template(
             "/".join([self.partition_template_path, 'nodes.sql']),
-            scid=scid, tid=tid
+            scid=scid, tid=tid, ptid=ptid
         )
         status, rset = self.conn.execute_2darray(SQL)
         if not status:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/static/js/partition.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/static/js/partition.js
index 14e015210..04a693ead 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/static/js/partition.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/static/js/partition.js
@@ -49,8 +49,7 @@ function(
       sqlCreateHelp: 'sql-createtable.html',
       dialogHelp: url_for('help.static', {'filename': 'table_dialog.html'}),
       hasScriptTypes: ['create'],
-      height: '95%',
-      width: '85%',
+      width: '650px',
       Init: function() {
         /* Avoid mulitple registration of menus */
         if (this.initialized)
@@ -865,7 +864,7 @@ function(
           canEdit: false, canDelete: true,
           customDeleteTitle: gettext('Detach Partition'),
           customDeleteMsg: gettext('Are you sure you wish to detach this partition?'),
-          columns:['is_attach', 'partition_name', 'values_from', 'values_to', 'values_in'],
+          columns:['is_attach', 'partition_name', 'is_default', 'values_from', 'values_to', 'values_in', 'values_modulus', 'values_remainder'],
           control: Backform.SubNodeCollectionControl.extend({
             row: Backgrid.PartitionRow,
             initialize: function() {
@@ -930,10 +929,30 @@ function(
         },{
           id: 'partition_note', label: gettext('Partition'),
           type: 'note', group: 'partition',
-          text: gettext('The control above is used to Create/Attach/Detach partitions.<br>' +
-            '<ul><li>Create Mode: User will be able to create N number of partitions. Mode switch control is disabled in this scenario.</li>' +
-            '<li>Edit Mode: User will be able to create/attach/detach N number of partitions. ' +
-            'In attach mode there will be list of suitable tables to be attached.</li></ul>'),
+          text: [
+            '<ul><li>',
+            '<strong>', gettext('Create a table: '), '</strong>',
+            gettext('User can create multiple partitions while creating new partitioned table. Operation switch is disabled in this scenario.'),
+            '</li><li>',
+            '<strong>', gettext('Edit existing table: '), '</strong>',
+            gettext('User can create/attach/detach multiple partitions. In attach operation user can select table from the list of suitable tables to be attached.'),
+            '</li><li>',
+            '<strong>', gettext('Default: '), '</strong>',
+            gettext('The default partition can store rows that do not fall into any existing partition’s range or list.'),
+            '</li><li>',
+            '<strong>', gettext('From/To/In input: '), '</strong>',
+            gettext('From/To/In input: Values for these fields must be quoted with single quote. For more than one partition key values must be comma(,) separated.'),
+            '</li><li>',
+            '<strong>', gettext('Example: From/To: '), '</strong>',
+            gettext('Enabled for range partition. Consider partitioned table with multiple keys of type Integer, then values should be specified like \'100\',\'200\'.'),
+            '</li><li>',
+            '<strong>', gettext('In: '), '</strong>',
+            gettext('Enabled for list partition. Values must be comma(,) separated and quoted with single quote.'),
+            '</li><li>',
+            '<strong>', gettext('Modulus/Remainder: '), '</strong>',
+            gettext('Enabled for hash partition.'),
+            '</li></ul>',
+          ].join(''),
           visible: function(m) {
             if(!_.isUndefined(m.node_info) && !_.isUndefined(m.node_info.server)
               && !_.isUndefined(m.node_info.server.version) &&
diff --git a/web/pgadmin/browser/utils.py b/web/pgadmin/browser/utils.py
index 0cc061db5..b7c8d2945 100644
--- a/web/pgadmin/browser/utils.py
+++ b/web/pgadmin/browser/utils.py
@@ -343,10 +343,8 @@ class NodeView(with_metaclass(MethodViewType, View)):
 
     def children(self, *args, **kwargs):
         """Build a list of treeview nodes from the child nodes."""
-        children = []
+        children = self._get_children_nodes(*args, **kwargs)
 
-        for module in self.blueprint.submodules:
-            children.extend(module.get_nodes(*args, **kwargs))
         # Return sorted nodes based on label
         return make_json_response(
             data=sorted(
@@ -354,8 +352,46 @@ class NodeView(with_metaclass(MethodViewType, View)):
             )
         )
 
+    def _get_children_nodes(self, *args, **kwargs):
+        """
+        Returns the list of children nodes for the current nodes. Override this
+        function for special cases only.
+
+        :param args:
+        :param kwargs: Parameters to generate the correct set of tree node.
+        :return: List of the children nodes
+        """
+        children = []
+
+        for module in self.blueprint.submodules:
+            children.extend(module.get_nodes(*args, **kwargs))
+
+        return children
+
 
 class PGChildNodeView(NodeView):
+
+    def _get_children_nodes(self, manager, **kwargs):
+        """
+        Returns the list of children nodes for the current nodes.
+
+        :param manager: Server Manager object
+        :param kwargs: Parameters to generate the correct set of browser tree
+          node
+        :return:
+        """
+        nodes = []
+        for module in self.blueprint.submodules:
+            if isinstance(module, PGChildModule):
+                if (
+                    manager is not None and
+                    module.BackendSupported(manager, **kwargs)
+                ):
+                    nodes.extend(module.get_nodes(**kwargs))
+            else:
+                nodes.extend(module.get_nodes(**kwargs))
+        return nodes
+
     def children(self, **kwargs):
         """Build a list of treeview nodes from the child nodes."""
 
@@ -388,21 +424,11 @@ class PGChildNodeView(NodeView):
                 )
             )
 
-        nodes = []
-        for module in self.blueprint.submodules:
-            if isinstance(module, PGChildModule):
-                if (
-                    manager is not None and
-                    module.BackendSupported(manager, **kwargs)
-                ):
-                    nodes.extend(module.get_nodes(**kwargs))
-            else:
-                nodes.extend(module.get_nodes(**kwargs))
-
         # Return sorted nodes based on label
         return make_json_response(
             data=sorted(
-                nodes, key=lambda c: c['label']
+                self._get_children_nodes(manager, **kwargs),
+                key=lambda c: c['label']
             )
         )
 


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [pgAdmin][RM4633] Bad view in partitioned tables
  2020-01-03 11:28 [pgAdmin][RM4633] Bad view in partitioned tables Akshay Joshi <[email protected]>
@ 2020-01-06 06:31 ` Khushboo Vashi <[email protected]>
  2020-01-06 09:31   ` Re: [pgAdmin][RM4633] Bad view in partitioned tables Akshay Joshi <[email protected]>
  0 siblings, 1 reply; 3+ messages in thread

From: Khushboo Vashi @ 2020-01-06 06:31 UTC (permalink / raw)
  To: Akshay Joshi <[email protected]>; +Cc: pgadmin-hackers

Hi Akshay,

On Fri, Jan 3, 2020 at 4:58 PM Akshay Joshi <[email protected]>
wrote:

> Hi Hackers
>
> Attached is the patch to support the view part of the multilevel
> partitions. Users can perform all the operations except creating the
> partitions as a partitioned table. Users can create a partition table
> separately and attach it as a partition of another partition table.
>
Multilevel partitions are now manageable through the tree view except
creating a partition table of existing partition (which you already
mentioned).
One more problem that we already discussed that automatic tree refresh of
the multilevel partitions is not working due to our structure which is
going to be handled by the new RM.

Some of the minor review comments.
- _get_children_nodes name can be changed as it more like private method
but we are using it outside of the class itself.
- Stats of partition table is not displayed, but I think that is not
related to this patch, so can be fixed later.

Thanks,
Khushboo

>
> There are two problems mentioned in the RM. I have fixed the first one and
> we won't fix the second problem as by design we decided to show Partitions
> like Schema->Table->Partitions
>
> Please review it.
> --
> *Thanks & Regards*
> *Akshay Joshi*
>
> *Sr. Software Architect*
> *EnterpriseDB Software India Private Limited*
> *Mobile: +91 976-788-8246*
>


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [pgAdmin][RM4633] Bad view in partitioned tables
  2020-01-03 11:28 [pgAdmin][RM4633] Bad view in partitioned tables Akshay Joshi <[email protected]>
  2020-01-06 06:31 ` Re: [pgAdmin][RM4633] Bad view in partitioned tables Khushboo Vashi <[email protected]>
@ 2020-01-06 09:31   ` Akshay Joshi <[email protected]>
  0 siblings, 0 replies; 3+ messages in thread

From: Akshay Joshi @ 2020-01-06 09:31 UTC (permalink / raw)
  To: Khushboo Vashi <[email protected]>; +Cc: pgadmin-hackers

On Mon, Jan 6, 2020 at 12:01 PM Khushboo Vashi <
[email protected]> wrote:

> Hi Akshay,
>
> On Fri, Jan 3, 2020 at 4:58 PM Akshay Joshi <[email protected]>
> wrote:
>
>> Hi Hackers
>>
>> Attached is the patch to support the view part of the multilevel
>> partitions. Users can perform all the operations except creating the
>> partitions as a partitioned table. Users can create a partition table
>> separately and attach it as a partition of another partition table.
>>
> Multilevel partitions are now manageable through the tree view except
> creating a partition table of existing partition (which you already
> mentioned).
> One more problem that we already discussed that automatic tree refresh of
> the multilevel partitions is not working due to our structure which is
> going to be handled by the new RM.
>

    New RM https://redmine.postgresql.org/issues/5064 has been created.

>
> Some of the minor review comments.
> - _get_children_nodes name can be changed as it more like private method
> but we are using it outside of the class itself.
>

    Fixed.

> - Stats of partition table is not displayed, but I think that is not
> related to this patch, so can be fixed later.
>

   I have verified/confirmed that in the case of the Partitioned table,
Statistics is visible only for the child node. In the case of the
multilevel partitioned table, Statistics will only be available of the last
child node which we are showing, so it's not a bug.

>
> Thanks,
> Khushboo
>
>>
>> There are two problems mentioned in the RM. I have fixed the first one
>> and we won't fix the second problem as by design we decided to show
>> Partitions like Schema->Table->Partitions
>>
>> Please review it.
>> --
>> *Thanks & Regards*
>> *Akshay Joshi*
>>
>> *Sr. Software Architect*
>> *EnterpriseDB Software India Private Limited*
>> *Mobile: +91 976-788-8246*
>>
>

-- 
*Thanks & Regards*
*Akshay Joshi*

*Sr. Software Architect*
*EnterpriseDB Software India Private Limited*
*Mobile: +91 976-788-8246*


^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2020-01-06 09:31 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-01-03 11:28 [pgAdmin][RM4633] Bad view in partitioned tables Akshay Joshi <[email protected]>
2020-01-06 06:31 ` Khushboo Vashi <[email protected]>
2020-01-06 09:31   ` Akshay Joshi <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox