FoundationDB/sql-layer — pull request #1129 by MMcM (2013-12-25 17:47:09+00:00)
Title: Complete the removal of ais.model.Types.

This final branch is larger than I had hoped it would be. But a number of things had to be changed to keep tests mostly the same and they have proven difficult to tease out into separate branches.

The driving goal is to make it possible to implement a rational type system using Types3, to which the old types (types1, more or less) were an impediment. While there is no need to get the MySQL adapter running again, I did not see any reason to make this impossible. At the same time, there is no attempt here to fix the MCOMPAT types and functions to make sense. Just to see that they are built on something that does (mostly).

As a result of the removal, there is now a single path from SQL parser types to Types3 to Postgres types. Previously, AIS types allowed for a Column's state that was impossible to represent or ambiguous. For example, TIMESTAMP in SQL must now turn into either MySQL DATETIME or MySQL TIMESTAMP (which has no more precision and special maintenance semantics). It cannot be one thing for CREATE TABLE and another for CAST. I chose to make it always DATETIME. Which means that it is still impossible to create a TIMESTAMP column via ordinary DDL, but tests (and the adapter) can. Keeping these tests working meant keeping track of the different TClass instances, as in the prerequisite branch.

Another major source of issues is BLOB. In MySQL, BLOB is in the middle of TINY-, MEDIUM- and LONGBLOB. The MBinary TClasses were not distinguishing this properly, making everything the same. Although our LOB support is minimal / nonexistent, I kept BLOB as the MySQL BLOB in the default (MySQL) bundle. This branch also fixes it to be binary on output (though strings can still be stored into it or compared with it). Conversely, among TINY-, MEDIUM-, TEXT and LONGTEXT, the standard keyword CLOB is not used in MySQL. So it can map to LONGTEXT without causing problems. This asymmetry would be more of an issue if we intended to build real ANSI types out of MCOMPAT, instead of beside it.

Since charset and collation are now part of the Column's type (along with nullability), and since TInstance cannot represent an unregistered charset / collation, it is not possible to *preserve* LOOSE DDL. It is mapped when the column is created. Many tests had unsupported / made-up collations. These had to be changed to real ones (from the very small set currently supported -- for no particularly good reason). Likewise, the default charset and collation on the AIS and Table (and planned for Schema when it is created directly) needs to use the same integer id encoding or else tests get spurious case / punctuation mismatches. At the same time, lots of confusion about the difference between any default specified on the table and the default default it inherits via the AIS is cleaned up.

Column had a special way of printing its type description, used in particular by OperatorCompilerTest. Since this now must derive ultimately from a TInstance, that must have a method for such printing. Which is now used consistently for parameter types and derived columns in those tests. As a result, many of the top lines of the .expected are changed a little.

A character literal should properly be CHAR(n). But overloading of CHAR + VARCHAR does not work completely and CAST was being added for innocent things such as LIKE. So, for now, I made literals VARCHAR. This problem in Types3 was hidden before by CHAR columns ultimately having a VARCHAR RowData encoding. Such encodings are almost gone now, being very local to FieldDef.

The type for VALUES is still computed by AST manipulation, rather than by the overload resolver. In order not to have to change that here, it needs to keep track of a TInstance as well as a DataTypeDescriptor. This is mainly a problem for the tests which create a TIMESTAMP column (impossible from normal DDL -- you would get DATETIME) and then try to insert via Postgres JDBC setTimestamp. If the column had only DataTypeDescriptor TIMESTAMP, that now implies MCOMPAT_ DATETIME and the YYYYMMDDHHMMSS long integer isn't compatible.