<!-- 
RSS generated by JIRA (8.3.4#803005-sha1:1f96e09b3c60279a408a2ae47be3c745f571388b) at Sat Feb 10 16:29:42 JST 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>PFS-JIRA</title>
    <link>https://pfspipe.ipmu.jp/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>8.3.4</version>
        <build-number>803005</build-number>
        <build-date>13-09-2019</build-date>
    </build-info>


<item>
            <title>[INSTRM-890] Decide on mechanism for saving unsigned integers to SQL.</title>
                <link>https://pfspipe.ipmu.jp/jira/browse/INSTRM-890</link>
                <project id="10300" key="INSTRM">Instrument control development</project>
                    <description>&lt;p&gt;Postgres does not provide unsigned integer types (nor does the SQL standard). At least one of our column types (for &lt;tt&gt;pfsDesignIds&lt;/tt&gt;, etc.) requires 64-bit unsigned ints, which do not have a larger type to upgrade to. Besides that, sqlAlchemy has no existing mechanism for synthesizing a new type. &lt;/p&gt;

&lt;p&gt;There is a &lt;tt&gt;pguint&lt;/tt&gt; extension which people seem to use. Or we could convert signed&amp;lt;-&amp;gt;unsigned above the SQL/sqlAlchemy layer. Others? MySQL has unsigned types, FWIW.&lt;/p&gt;

&lt;p&gt;This is not a problem for FITS. For tables, TSCAL and TZERO do the conversion, and for header cards the content of the integer field is (surprisingly) not constrained.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://pfspipe.ipmu.jp/jira/secure/ViewProfile.jspa?name=kiyoto.yabe&quot; class=&quot;user-hover&quot; rel=&quot;kiyoto.yabe&quot;&gt;Kiyoto Yabe&lt;/a&gt;? &lt;a href=&quot;https://pfspipe.ipmu.jp/jira/secure/ViewProfile.jspa?name=rhl&quot; class=&quot;user-hover&quot; rel=&quot;rhl&quot;&gt;rhl&lt;/a&gt;? &lt;a href=&quot;https://pfspipe.ipmu.jp/jira/secure/ViewProfile.jspa?name=price&quot; class=&quot;user-hover&quot; rel=&quot;price&quot;&gt;price&lt;/a&gt;?&lt;/p&gt;</description>
                <environment></environment>
        <key id="14195">INSTRM-890</key>
            <summary>Decide on mechanism for saving unsigned integers to SQL.</summary>
                <type id="3" iconUrl="https://pfspipe.ipmu.jp/jira/secure/viewavatar?size=xsmall&amp;avatarId=10518&amp;avatarType=issuetype">Task</type>
                                            <priority id="10000" iconUrl="https://pfspipe.ipmu.jp/jira/images/icons/priorities/medium.svg">Normal</priority>
                        <status id="1" iconUrl="https://pfspipe.ipmu.jp/jira/images/icons/statuses/open.png" description="The issue is open and ready for the assignee to start work on it.">Open</status>
                    <statusCategory id="2" key="new" colorName="blue-gray"/>
                                    <resolution id="-1">Unresolved</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="cloomis">cloomis</reporter>
                        <labels>
                            <label>opDB</label>
                    </labels>
                <created>Mon, 27 Jan 2020 22:27:01 +0000</created>
                <updated>Fri, 30 Oct 2020 15:05:13 +0000</updated>
                                                                                <due></due>
                            <votes>0</votes>
                                    <watches>3</watches>
                                                                <comments>
                            <comment id="16645" author="kiyoto.yabe" created="Tue, 28 Jan 2020 00:04:31 +0000"  >&lt;p&gt;I was proposing to use `NUMERIC` instead but this may not be a good idea because of performance etc.&lt;/p&gt;</comment>
                            <comment id="16646" author="cloomis" created="Tue, 28 Jan 2020 12:52:35 +0000"  >&lt;p&gt;I can&apos;t believe performance would really matter: we do not &lt;em&gt;operate&lt;/em&gt; on the values besides = and maybe !=. &lt;/p&gt;

&lt;p&gt;But sqlalchemy wants the python side of Numerics to be a float or a python Decimal, neither of which is directly useable. If we need to subclass or otherwise add sqlalchemy conversion/cast logic, I think we would be better off doing that for their Integer or BigInt types, where we could easily convert between unsigned and signed values. &lt;/p&gt;

&lt;p&gt;That said, I do not &lt;em&gt;actually&lt;/em&gt; know the right way do do this. Maybe something in &lt;a href=&quot;https://docs.sqlalchemy.org/en/13/core/custom_types.html#creating-new-types&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;https://docs.sqlalchemy.org/en/13/core/custom_types.html#creating-new-types&lt;/a&gt; maybe, with &lt;tt&gt;signed = unsigned ^ (1&amp;lt;&amp;lt;63)&lt;/tt&gt; as the cast?&lt;/p&gt;</comment>
                            <comment id="18013" author="kiyoto.yabe" created="Fri, 30 Oct 2020 05:58:13 +0000"  >&lt;p&gt;I tested the Postgres extension &lt;a href=&quot;https://github.com/petere/pguint&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;pguint&lt;/a&gt;&#160;in my local Linux machine with PostgreSQL 10.14. Although the installation was OK, I got unknown segfault when I put any value into a table with `uint8` datatype. The repository seems to be maintained by only one person and I&apos;m just worried about using that unstable extension in opDB.&#160;&lt;/p&gt;

&lt;p&gt;I also tested a signed - unsigned conversion in sqlalchemy side while the datatype of the column is `bigint` implementing `model.py` based on the link Craig suggested like this:&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
&lt;span class=&quot;code-keyword&quot;&gt;class &lt;/span&gt;UnsignedBigInteger(TypeDecorator):    
    impl = BigInteger    def __init__(self, *args, **kwargs):
    TypeDecorator.__init__(self, *args, **kwargs)    
    def process_bind_param(self, value, dialect):
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; value is not None:
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; value - (1 &amp;lt;&amp;lt; 63)    
    def process_result_value(self, value, dialect):
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; value is not None:
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; value + (1 &amp;lt;&amp;lt; 63)

&lt;span class=&quot;code-keyword&quot;&gt;class &lt;/span&gt;pfs_visit(Base):
    &apos;&apos;&apos;Tracks the Gen2 visit identifier.
    This is the fundamental identifier &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; all instrument exposures (MCS, AGC, SPS)
    &apos;&apos;&apos;
    __tablename__ = &lt;span class=&quot;code-quote&quot;&gt;&apos;pfs_visit&apos;&lt;/span&gt;    
    pfs_visit_id = Column(&lt;span class=&quot;code-object&quot;&gt;Integer&lt;/span&gt;, primary_key=True, unique=True, autoincrement=False)
    pfs_visit_description = Column(&lt;span class=&quot;code-object&quot;&gt;String&lt;/span&gt;)
    pfs_design_id = Column(UnsignedBigInteger)   
    
    def __init__(self, pfs_visit_id, pfs_visit_description, pfs_design_id):
        self.pfs_visit_id = pfs_visit_id
        self.pfs_visit_description = pfs_visit_description
        self.pfs_design_id = pfs_design_id
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;I think this works well. I can insert pfsDesignId=1 like&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
utils.insert(url, &lt;span class=&quot;code-quote&quot;&gt;&apos;pfs_visit&apos;&lt;/span&gt;, pd.DataFrame({&lt;span class=&quot;code-quote&quot;&gt;&apos;pfs_visit_id&apos;&lt;/span&gt;: [120981, 120982, 120983], &lt;span class=&quot;code-quote&quot;&gt;&apos;pfs_visit_description&apos;&lt;/span&gt;: [&lt;span class=&quot;code-quote&quot;&gt;&apos;test&apos;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&apos;test&apos;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&apos;test&apos;&lt;/span&gt;], &lt;span class=&quot;code-quote&quot;&gt;&apos;pfs_design_id&apos;&lt;/span&gt;: [pfsDesignId, pfsDesignId, pfsDesignId]}))
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;and see&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
develop=# select * from pfs_visit; pfs_visit_id | pfs_visit_description |&#160; &#160; pfs_design_id&#160; &#160; &#160; 
--------------+-----------------------+---------------------- &#160;&#160; &#160; &#160; 
120981 | test&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; | -9223372036854775807 &#160;&#160; &#160; &#160; 
120982 | test&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; | -9223372036854775807 &#160;&#160; &#160; &#160; 
120983 | test&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; | -9223372036854775807 
(3 rows)
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;I fetch the table like&#160;&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
res = utils.fetch_all(url, &lt;span class=&quot;code-quote&quot;&gt;&apos;pfs_visit&apos;&lt;/span&gt;) 
print(res)
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;and see&#160;&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
&#160;&#160; pfs_visit_id pfs_visit_description&#160; pfs_design_id 
0&#160; &#160; &#160; &#160; 120981&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; test&#160; &#160; &#160; &#160; &#160; &#160; &#160; 1 
1&#160; &#160; &#160; &#160; 120982&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; test&#160; &#160; &#160; &#160; &#160; &#160; &#160; 1 
2&#160; &#160; &#160; &#160; 120983&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; test&#160; &#160; &#160; &#160; &#160; &#160; &#160; 1
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;So I think, as long as we use opDB package, we can treat unsigned bigint without caring about the conversion. We need to worry about that if we want access opDB directly. What do you think, &lt;a href=&quot;https://pfspipe.ipmu.jp/jira/secure/ViewProfile.jspa?name=cloomis&quot; class=&quot;user-hover&quot; rel=&quot;cloomis&quot;&gt;cloomis&lt;/a&gt;&#160;?&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="18014" author="cloomis" created="Fri, 30 Oct 2020 15:05:13 +0000"  >&lt;p&gt;I was hoping that (using signed integers inside the db, and converting simply on select/insert) would work. The &lt;em&gt;bits&lt;/em&gt; are the same and should not change if we do that right. &lt;/p&gt;

&lt;p&gt;So yes, I like that.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10000">
                    <name>Blocks</name>
                                            <outwardlinks description="blocks">
                                        <issuelink>
            <issuekey id="15004">INSTRM-1096</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10500" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                            <customfield id="customfield_10010" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>0|zzs0kw:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        </customfields>
    </item>
</channel>
</rss>