MCPcopy Create free account
hub / github.com/apache/datafusion / calc_inline_constraints_from_columns

Function calc_inline_constraints_from_columns

datafusion/sql/src/statement.rs:105–221  ·  view source on GitHub ↗

Construct `TableConstraint`(s) for the given columns by iterating over `columns` and extracting individual inline constraint definitions.

(columns: &[ColumnDef])

Source from the content-addressed store, hash-verified

103/// Construct `TableConstraint`(s) for the given columns by iterating over
104/// `columns` and extracting individual inline constraint definitions.
105fn calc_inline_constraints_from_columns(columns: &[ColumnDef]) -> Vec<TableConstraint> {
106 let mut constraints: Vec<TableConstraint> = vec![];
107 for column in columns {
108 for ast::ColumnOptionDef { name, option } in &column.options {
109 match option {
110 ast::ColumnOption::Unique(UniqueConstraint {
111 characteristics,
112 name,
113 index_name: _index_name,
114 index_type_display: _index_type_display,
115 index_type: _index_type,
116 columns: _column,
117 index_options: _index_options,
118 nulls_distinct: _nulls_distinct,
119 }) => constraints.push(TableConstraint::Unique(UniqueConstraint {
120 name: name.clone(),
121 index_name: None,
122 index_type_display: ast::KeyOrIndexDisplay::None,
123 index_type: None,
124 columns: vec![IndexColumn {
125 column: OrderByExpr {
126 expr: SQLExpr::Identifier(column.name.clone()),
127 options: OrderByOptions {
128 asc: None,
129 nulls_first: None,
130 },
131 with_fill: None,
132 },
133 operator_class: None,
134 }],
135 index_options: vec![],
136 characteristics: *characteristics,
137 nulls_distinct: NullsDistinctOption::None,
138 })),
139 ast::ColumnOption::PrimaryKey(PrimaryKeyConstraint {
140 characteristics,
141 name: _name,
142 index_name: _index_name,
143 index_type: _index_type,
144 columns: _columns,
145 index_options: _index_options,
146 }) => {
147 constraints.push(TableConstraint::PrimaryKey(PrimaryKeyConstraint {
148 name: name.clone(),
149 index_name: None,
150 index_type: None,
151 columns: vec![IndexColumn {
152 column: OrderByExpr {
153 expr: SQLExpr::Identifier(column.name.clone()),
154 options: OrderByOptions {
155 asc: None,
156 nulls_first: None,
157 },
158 with_fill: None,
159 },
160 operator_class: None,
161 }],
162 index_options: vec![],

Calls 2

pushMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…