Skip to content

Commit 03b19c9

Browse files
authored
feat(format): add more constraint metadata to GetObjects (#4008)
- Add `constraint_expression` - Add various fields for foreign keys Closes #3987. Closes #3989.
1 parent 0b5a953 commit 03b19c9

2 files changed

Lines changed: 264 additions & 16 deletions

File tree

  • c/include/arrow-adbc
  • go/adbc/drivermgr/arrow-adbc

c/include/arrow-adbc/adbc.h

Lines changed: 132 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,10 @@ const struct AdbcError* AdbcErrorFromArrayStream(struct ArrowArrayStream* stream
683683
/// \see ADBC_ERROR_VENDOR_CODE_PRIVATE_DATA
684684
#define ADBC_INFO_FEATURE_ERROR_METADATA 250
685685

686+
/// \defgroup adbc-catalog-metadata ADBC Catalog Metadata Constants
687+
/// Constants for catalog metadata.
688+
/// @{
689+
686690
/// \brief Return metadata on catalogs, schemas, tables, and columns.
687691
///
688692
/// \see AdbcConnectionGetObjects
@@ -708,6 +712,88 @@ const struct AdbcError* AdbcErrorFromArrayStream(struct ArrowArrayStream* stream
708712
/// \see AdbcConnectionGetObjects
709713
#define ADBC_OBJECT_DEPTH_COLUMNS ADBC_OBJECT_DEPTH_ALL
710714

715+
/// \brief This foreign key does not allow update of the corresponding primary
716+
/// key.
717+
///
718+
/// \note Value corresponds to JDBC `DatabaseMetaData#importedKeyNoAction`.
719+
///
720+
/// \see AdbcConnectionGetObjects
721+
#define ADBC_CONSTRAINT_ACTION_NO_ACTION 3
722+
723+
/// \brief This foreign key will be updated/deleted with corresponding primary
724+
/// key.
725+
///
726+
/// \note Value corresponds to JDBC `DatabaseMetaData#importedKeyCascade`.
727+
///
728+
/// \see AdbcConnectionGetObjects
729+
#define ADBC_CONSTRAINT_ACTION_CASCADE 0
730+
731+
/// \brief This foreign key will be set to NULL if its corresponding primary
732+
/// key is updated or deleted.
733+
///
734+
/// \note Value corresponds to JDBC `DatabaseMetaData#importedKeySetNull`.
735+
///
736+
/// \see AdbcConnectionGetObjects
737+
#define ADBC_CONSTRAINT_ACTION_SET_NULL 2
738+
739+
/// \brief This foreign key will be set to its default if its corresponding
740+
/// primary key is updated or deleted.
741+
///
742+
/// \note Value corresponds to JDBC `DatabaseMetaData#importedKeySetDefault`.
743+
///
744+
/// \see AdbcConnectionGetObjects
745+
#define ADBC_CONSTRAINT_ACTION_SET_DEFAULT 4
746+
747+
/// \brief Similar to ADBC_CONSTRAINT_ACTION_NO_ACTION but may be interpreted
748+
/// differently by the vendor (e.g., raise an error immediately instead of
749+
/// allowing the check to be deferred).
750+
///
751+
/// \note Value corresponds to JDBC `DatabaseMetaData#importedKeyRestrict`.
752+
///
753+
/// \see AdbcConnectionGetObjects
754+
#define ADBC_CONSTRAINT_ACTION_RESTRICT 1
755+
756+
/// \brief This constraint is deferrable, and is initially deferred.
757+
///
758+
/// \note Value corresponds to JDBC `DatabaseMetaData#importedKeyInitiallyDeferred`.
759+
///
760+
/// \see AdbcConnectionGetObjects
761+
#define ADBC_CONSTRAINT_DEFERRABLE_DEFERRED 5
762+
763+
/// \brief This constraint is deferrable, but is initially immediate.
764+
///
765+
/// \note Value corresponds to JDBC `DatabaseMetaData#importedKeyInitiallyImmediate`.
766+
///
767+
/// \see AdbcConnectionGetObjects
768+
#define ADBC_CONSTRAINT_DEFERRABLE_IMMEDIATE 6
769+
770+
/// \brief This constraint may not be deferred.
771+
///
772+
/// \note Value corresponds to JDBC `DatabaseMetaData#importedKeyNotDeferrable`.
773+
///
774+
/// \see AdbcConnectionGetObjects
775+
#define ADBC_CONSTRAINT_NOT_DEFERRABLE 7
776+
777+
/// \brief This foreign key allows any of the foreign key columns to be NULL;
778+
/// if so, no match is required in the referenced table.
779+
///
780+
/// \see AdbcConnectionGetObjects
781+
#define ADBC_CONSTRAINT_MATCH_SIMPLE 0
782+
783+
/// \brief This foreign key only allows foreign key columns to be NULL if all
784+
/// of them are NULL; if so, no match is required in the referenced table.
785+
///
786+
/// \see AdbcConnectionGetObjects
787+
#define ADBC_CONSTRAINT_MATCH_FULL 1
788+
789+
/// \brief This foreign key allows any of the foreign key columns to be NULL;
790+
/// if so, non-NULL columns must still match.
791+
///
792+
/// \see AdbcConnectionGetObjects
793+
#define ADBC_CONSTRAINT_MATCH_PARTIAL 2
794+
795+
/// @}
796+
711797
/// \defgroup adbc-table-statistics ADBC Statistic Types
712798
/// Standard statistic names for AdbcConnectionGetStatistics.
713799
/// @{
@@ -1950,20 +2036,58 @@ AdbcStatusCode AdbcConnectionGetInfo(struct AdbcConnection* connection,
19502036
/// | constraint_type | utf8 not null | (1) |
19512037
/// | constraint_column_names | list<utf8> not null | (2) |
19522038
/// | constraint_column_usage | list<USAGE_SCHEMA> | (3) |
1953-
///
1954-
/// 1. One of 'CHECK', 'FOREIGN KEY', 'PRIMARY KEY', or 'UNIQUE'.
2039+
/// | constraint_expression | utf8 | (4) |
2040+
/// | constraint_update_rule | int16 | (5) |
2041+
/// | constraint_delete_rule | int16 | (5) |
2042+
/// | constraint_enforced | bool | (6) |
2043+
/// | constraint_deferrability | int16 | (7) |
2044+
/// | constraint_match_type | int16 | (8) |
2045+
///
2046+
/// 1. One of 'CHECK', 'FOREIGN KEY', 'PRIMARY KEY', or 'UNIQUE', or a
2047+
/// vendor-specific type.
19552048
/// 2. The columns on the current table that are constrained, in
19562049
/// order.
19572050
/// 3. For FOREIGN KEY only, the referenced table and columns.
2051+
/// 4. [Since version 1.2.0] The vendor-specific definition of the constraint
2052+
/// (e.g. the SQL expression to be checked). This field is optional.
2053+
/// 5. [Since version 1.2.0] The action to be taken when the primary key is
2054+
/// updated or deleted. The value is one of the ADBC_CONSTRAINT_ACTION_
2055+
/// constants. This field is optional.
2056+
/// 6. [Since version 1.2.0] Whether the constraint is currently enabled.
2057+
/// This field is optional.
2058+
/// 7. [Since version 1.2.0] Whether the constraint can be deferred, and if
2059+
/// so, whether it starts deferred. The value is one of the
2060+
/// ADBC_CONSTRAINT_DEFERRABLE_ constants or
2061+
/// ADBC_CONSTRAINT_NOT_DEFERRABLE. This field is optional.
2062+
/// 8. [Since version 1.2.0] How the foreign key constraint should be matched.
2063+
/// The value is one of the ADBC_CONSTRAINT_MATCH_ constants. This field
2064+
/// is optional.
19582065
///
19592066
/// USAGE_SCHEMA is a Struct with fields:
19602067
///
1961-
/// | Field Name | Field Type |
1962-
/// |--------------------------|-------------------------|
1963-
/// | fk_catalog | utf8 |
1964-
/// | fk_db_schema | utf8 |
1965-
/// | fk_table | utf8 not null |
1966-
/// | fk_column_name | utf8 not null |
2068+
/// | Field Name | Field Type | Comments |
2069+
/// |--------------------------|-------------------------|----------|
2070+
/// | fk_catalog | utf8 | |
2071+
/// | fk_db_schema | utf8 | |
2072+
/// | fk_table | utf8 not null | |
2073+
/// | fk_column_name | utf8 not null | |
2074+
/// | fk_key_seq | int32 | (1) |
2075+
/// | fk_pk_name | utf8 | (2) |
2076+
///
2077+
/// 1. [Since version 1.2.0] The ordinal position of the column within the
2078+
/// foreign key. If present, the driver should sort the rows on this
2079+
/// column. This field is optional.
2080+
/// 2. [Since version 1.2.0] The name of the referenced primary key. This
2081+
/// field is optional.
2082+
///
2083+
/// Starting in version 1.2.0, optional fields were introduced to the schema.
2084+
/// Optional fields may not be present in the returned schema/data and
2085+
/// applications should check for their presence before using them. Drivers
2086+
/// may choose to include optional fields (with null values) even if not
2087+
/// supported, but are not required to. If an optional field is present, all
2088+
/// optional fields defined before it in the schema must be present (but the
2089+
/// values may still be null if the driver does not actually support that
2090+
/// field).
19672091
///
19682092
/// This AdbcConnection must outlive the returned ArrowArrayStream.
19692093
///

go/adbc/drivermgr/arrow-adbc/adbc.h

Lines changed: 132 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)