Skip to content

Commit 5f1e7cd

Browse files
authored
fix(compass-indexes): remove unique option on columnstore index creation COMPASS-5830 (#3098)
1 parent d8d129a commit 5f1e7cd

File tree

8 files changed

+125
-107
lines changed

8 files changed

+125
-107
lines changed

packages/compass-indexes/src/components/create-index-modal/create-index-modal.jsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import { toggleIsUnique } from '../../modules/create-index/is-unique';
3232
import { toggleIsPartialFilterExpression } from '../../modules/create-index/is-partial-filter-expression';
3333
import { toggleIsTtl } from '../../modules/create-index/is-ttl';
3434
import { changeTtl } from '../../modules/create-index/ttl';
35-
import { toggleIsWildcard } from '../../modules/create-index/is-wildcard';
36-
import { toggleIsColumnstore } from '../../modules/create-index/is-columnstore';
35+
import { toggleHasWildcardProjection } from '../../modules/create-index/has-wildcard-projection';
36+
import { toggleHasColumnstoreProjection } from '../../modules/create-index/has-columnstore-projection';
3737
import { changeWildcardProjection } from '../../modules/create-index/wildcard-projection';
3838
import { changeColumnstoreProjection } from '../../modules/create-index/columnstore-projection';
3939
import { changePartialFilterExpression } from '../../modules/create-index/partial-filter-expression';
@@ -64,8 +64,8 @@ class CreateIndexModal extends PureComponent {
6464
isUnique: PropTypes.bool.isRequired,
6565
isTtl: PropTypes.bool.isRequired,
6666
ttl: PropTypes.string.isRequired,
67-
isWildcard: PropTypes.bool.isRequired,
68-
isColumnstore: PropTypes.bool.isRequired,
67+
hasWildcardProjection: PropTypes.bool.isRequired,
68+
hasColumnstoreProjection: PropTypes.bool.isRequired,
6969
wildcardProjection: PropTypes.string.isRequired,
7070
columnstoreProjection: PropTypes.string.isRequired,
7171
isPartialFilterExpression: PropTypes.bool.isRequired,
@@ -83,8 +83,8 @@ class CreateIndexModal extends PureComponent {
8383
toggleShowOptions: PropTypes.func.isRequired,
8484
toggleIsBackground: PropTypes.func.isRequired,
8585
toggleIsTtl: PropTypes.func.isRequired,
86-
toggleIsWildcard: PropTypes.func.isRequired,
87-
toggleIsColumnstore: PropTypes.func.isRequired,
86+
toggleHasWildcardProjection: PropTypes.func.isRequired,
87+
toggleHasColumnstoreProjection: PropTypes.func.isRequired,
8888
toggleIsPartialFilterExpression: PropTypes.func.isRequired,
8989
toggleIsCustomCollation: PropTypes.func.isRequired,
9090
resetForm: PropTypes.func.isRequired,
@@ -254,10 +254,12 @@ class CreateIndexModal extends PureComponent {
254254
name="Wildcard Projection"
255255
data-test-id="toggle-is-wildcard"
256256
titleClassName={styles['create-index-modal-options-param']}
257-
checked={this.props.isWildcard}
257+
checked={this.props.hasWildcardProjection}
258258
helpUrl={getIndexHelpLink('WILDCARD')}
259259
onClickHandler={() =>
260-
this.props.toggleIsWildcard(!this.props.isWildcard)
260+
this.props.toggleHasWildcardProjection(
261+
!this.props.hasWildcardProjection
262+
)
261263
}
262264
onLinkClickHandler={this.props.openLink}
263265
/>
@@ -268,10 +270,12 @@ class CreateIndexModal extends PureComponent {
268270
name="Columnstore Projection"
269271
data-test-id="toggle-is-columnstore"
270272
titleClassName={styles['create-index-modal-options-param']}
271-
checked={this.props.isColumnstore}
273+
checked={this.props.hasColumnstoreProjection}
272274
helpUrl={getIndexHelpLink('COLUMNSTORE')}
273275
onClickHandler={() =>
274-
this.props.toggleIsColumnstore(!this.props.isColumnstore)
276+
this.props.toggleHasColumnstoreProjection(
277+
!this.props.hasColumnstoreProjection
278+
)
275279
}
276280
onLinkClickHandler={this.props.openLink}
277281
/>
@@ -297,7 +301,7 @@ class CreateIndexModal extends PureComponent {
297301
}
298302
}
299303
renderWildcard() {
300-
if (this.props.showOptions && this.props.isWildcard) {
304+
if (this.props.showOptions && this.props.hasWildcardProjection) {
301305
return (
302306
<div className={styles['create-index-modal-options-param-wrapper']}>
303307
<ModalInput
@@ -313,7 +317,7 @@ class CreateIndexModal extends PureComponent {
313317
}
314318
}
315319
renderColumnstoreIndexOptions() {
316-
if (this.props.showOptions && this.props.isColumnstore) {
320+
if (this.props.showOptions && this.props.hasColumnstoreProjection) {
317321
return (
318322
<div className={styles['create-index-modal-options-param-wrapper']}>
319323
<ModalInput
@@ -494,8 +498,8 @@ const mapStateToProps = (state) => ({
494498
isBackground: state.isBackground,
495499
isTtl: state.isTtl,
496500
ttl: state.ttl,
497-
isWildcard: state.isWildcard,
498-
isColumnstore: state.isColumnstore,
501+
hasWildcardProjection: state.hasWildcardProjection,
502+
hasColumnstoreProjection: state.hasColumnstoreProjection,
499503
columnstoreProjection: state.columnstoreProjection,
500504
wildcardProjection: state.wildcardProjection,
501505
isUnique: state.isUnique,
@@ -520,8 +524,8 @@ const MappedCreateIndexModal = connect(mapStateToProps, {
520524
toggleIsVisible,
521525
toggleIsBackground,
522526
toggleIsTtl,
523-
toggleIsWildcard,
524-
toggleIsColumnstore,
527+
toggleHasWildcardProjection,
528+
toggleHasColumnstoreProjection,
525529
toggleIsUnique,
526530
toggleIsPartialFilterExpression,
527531
toggleIsCustomCollation,

packages/compass-indexes/src/components/create-index-modal/create-index-modal.spec.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('CreateIndexModal [Component]', function () {
1919
let toggleIsTtlSpy;
2020
let toggleIsPartialFilterExpressionSpy;
2121
let toggleIsCustomCollationSpy;
22-
let toggleIsColumnstoreSpy;
22+
let toggleHasColumnstoreProjectionSpy;
2323
let resetFormSpy;
2424
let createIndexSpy;
2525
let openLinkSpy;
@@ -209,7 +209,7 @@ describe('CreateIndexModal [Component]', function () {
209209
toggleIsTtlSpy = sinon.spy();
210210
toggleIsPartialFilterExpressionSpy = sinon.spy();
211211
toggleIsCustomCollationSpy = sinon.spy();
212-
toggleIsColumnstoreSpy = sinon.spy();
212+
toggleHasColumnstoreProjectionSpy = sinon.spy();
213213
resetFormSpy = sinon.spy();
214214
createIndexSpy = sinon.spy();
215215
openLinkSpy = sinon.spy();
@@ -246,7 +246,7 @@ describe('CreateIndexModal [Component]', function () {
246246
toggleIsTtl={toggleIsTtlSpy}
247247
toggleIsPartialFilterExpression={toggleIsPartialFilterExpressionSpy}
248248
toggleIsCustomCollation={toggleIsCustomCollationSpy}
249-
toggleIsColumnstore={toggleIsColumnstoreSpy}
249+
toggleHasColumnstoreProjection={toggleHasColumnstoreProjectionSpy}
250250
resetForm={resetFormSpy}
251251
createIndex={createIndexSpy}
252252
openLink={openLinkSpy}
@@ -270,7 +270,7 @@ describe('CreateIndexModal [Component]', function () {
270270
toggleIsTtlSpy = null;
271271
toggleIsPartialFilterExpressionSpy = null;
272272
toggleIsCustomCollationSpy = null;
273-
toggleIsColumnstoreSpy = null;
273+
toggleHasColumnstoreProjectionSpy = null;
274274
resetFormSpy = null;
275275
createIndexSpy = null;
276276
openLinkSpy = null;
@@ -373,12 +373,12 @@ describe('CreateIndexModal [Component]', function () {
373373
});
374374
});
375375
context('columnstoreIndexes', function () {
376-
it('calls the toggleIsColumnstore function', function () {
376+
it('calls the toggleHasColumnstoreProjection function', function () {
377377
component
378378
.find('[data-test-id="toggle-is-columnstore"]')
379379
.find('[type="checkbox"]')
380380
.simulate('change', { target: { checked: true } });
381-
expect(toggleIsColumnstoreSpy.called).to.equal(true);
381+
expect(toggleHasColumnstoreProjectionSpy.called).to.equal(true);
382382
});
383383
});
384384
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Change has columnstore projection action name.
3+
*/
4+
export const TOGGLE_HAS_COLUMNSTORE_PROJECTION =
5+
'indexes/create-indexes/is-columnstore/TOGGLE_HAS_COLUMNSTORE_PROJECTION';
6+
7+
type HasColumnstoreProjectionState = boolean;
8+
9+
/**
10+
* The initial state of the has columnstore projection attribute.
11+
*/
12+
export const INITIAL_STATE: HasColumnstoreProjectionState = false;
13+
14+
type hasColumnstoreProjectionAction = {
15+
type: typeof TOGGLE_HAS_COLUMNSTORE_PROJECTION;
16+
hasColumnstoreProjection: boolean;
17+
};
18+
19+
/**
20+
* Reducer function for handle state changes to has columnstore projection.
21+
*
22+
* @param {Boolean} state - The has columnstore state.
23+
* @param {Object} action - The action.
24+
*
25+
* @returns {Array} The new state.
26+
*/
27+
export default function reducer(
28+
state = INITIAL_STATE,
29+
action: hasColumnstoreProjectionAction
30+
): HasColumnstoreProjectionState {
31+
if (action.type === TOGGLE_HAS_COLUMNSTORE_PROJECTION) {
32+
return action.hasColumnstoreProjection;
33+
}
34+
return state;
35+
}
36+
37+
/**
38+
* The toggle has columnstore projection action creator.
39+
*
40+
* @param {Boolean} hasColumnstoreProjection - has columnstore projection.
41+
*
42+
* @returns {Object} The action.
43+
*/
44+
export const toggleHasColumnstoreProjection = (
45+
hasColumnstoreProjection: HasColumnstoreProjectionState
46+
): hasColumnstoreProjectionAction => ({
47+
type: TOGGLE_HAS_COLUMNSTORE_PROJECTION,
48+
hasColumnstoreProjection: hasColumnstoreProjection,
49+
});

packages/compass-indexes/src/modules/create-index/is-wildcard.js renamed to packages/compass-indexes/src/modules/create-index/has-wildcard-projection.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* Change is wildcard action name.
33
*/
4-
export const TOGGLE_IS_WILDCARD =
5-
'indexes/create-indexes/is-wildcard/TOGGLE_IS_WILDCARD';
4+
export const TOGGLE_HAS_WILDCARD_PROJECTION =
5+
'indexes/create-indexes/has-wildcard-projection/TOGGLE_HAS_WILDCARD_PROJECTION';
66

77
/**
88
* The initial state of the is writable attribute.
@@ -18,20 +18,20 @@ export const INITIAL_STATE = false;
1818
* @returns {Array} The new state.
1919
*/
2020
export default function reducer(state = INITIAL_STATE, action) {
21-
if (action.type === TOGGLE_IS_WILDCARD) {
22-
return action.isWildcard;
21+
if (action.type === TOGGLE_HAS_WILDCARD_PROJECTION) {
22+
return action.hasWildcardProjection;
2323
}
2424
return state;
2525
}
2626

2727
/**
2828
* The toggle is wildcard action creator.
2929
*
30-
* @param {Boolean} isWildcard - Is wildcard.
30+
* @param {Boolean} hasWildcardProjection - Is wildcard.
3131
*
3232
* @returns {Object} The action.
3333
*/
34-
export const toggleIsWildcard = (isWildcard) => ({
35-
type: TOGGLE_IS_WILDCARD,
36-
isWildcard: isWildcard,
34+
export const toggleHasWildcardProjection = (hasWildcardProjection) => ({
35+
type: TOGGLE_HAS_WILDCARD_PROJECTION,
36+
hasWildcardProjection: hasWildcardProjection,
3737
});

packages/compass-indexes/src/modules/create-index/is-wildcard.spec.js renamed to packages/compass-indexes/src/modules/create-index/has-wildcard-projection.spec.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ import { expect } from 'chai';
22

33
import reducer, {
44
INITIAL_STATE,
5-
toggleIsWildcard,
6-
TOGGLE_IS_WILDCARD,
7-
} from '../create-index/is-wildcard';
5+
toggleHasWildcardProjection,
6+
TOGGLE_HAS_WILDCARD_PROJECTION,
7+
} from '../create-index/has-wildcard-projection';
88

9-
describe('create index is wildcard module', function () {
9+
describe('create index has wildcard projection module', function () {
1010
describe('#reducer', function () {
1111
context('when an action is provided', function () {
1212
it('returns the new state', function () {
13-
expect(reducer(undefined, toggleIsWildcard(true))).to.equal(true);
13+
expect(reducer(undefined, toggleHasWildcardProjection(true))).to.equal(
14+
true
15+
);
1416
});
1517
});
1618

@@ -21,11 +23,11 @@ describe('create index is wildcard module', function () {
2123
});
2224
});
2325

24-
describe('#toggleIsWildcard', function () {
26+
describe('#toggleHasWildcardProjection', function () {
2527
it('returns the action', function () {
26-
expect(toggleIsWildcard(false)).to.deep.equal({
27-
type: TOGGLE_IS_WILDCARD,
28-
isWildcard: false,
28+
expect(toggleHasWildcardProjection(false)).to.deep.equal({
29+
type: TOGGLE_HAS_WILDCARD_PROJECTION,
30+
hasWildcardProjection: false,
2931
});
3032
});
3133
});

packages/compass-indexes/src/modules/create-index/index.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ import isUnique, {
4141
import isTtl, {
4242
INITIAL_STATE as IS_TTL_INITIAL_STATE,
4343
} from '../create-index/is-ttl';
44-
import isWildcard, {
45-
INITIAL_STATE as IS_WILDCARD_INITIAL_STATE,
46-
} from '../create-index/is-wildcard';
47-
import isColumnstore, {
48-
INITIAL_STATE as IS_COLUMNSTORE_INITIAL_STATE,
49-
} from '../create-index/is-columnstore';
44+
import hasWildcardProjection, {
45+
INITIAL_STATE as HAS_WILDCARD_PROJECTION_INITIAL_STATE,
46+
} from './has-wildcard-projection';
47+
import hasColumnstoreProjection, {
48+
INITIAL_STATE as HAS_COLUMNSTORE_PROJECTION_INITIAL_STATE,
49+
} from '../create-index/has-columnstore-projection';
5050
import isPartialFilterExpression, {
5151
INITIAL_STATE as IS_PARTIAL_FILTER_EXPRESSION_INITIAL_STATE,
5252
} from '../create-index/is-partial-filter-expression';
@@ -90,8 +90,8 @@ const reducer = combineReducers({
9090
isBackground,
9191
isUnique,
9292
isTtl,
93-
isWildcard,
94-
isColumnstore,
93+
hasWildcardProjection,
94+
hasColumnstoreProjection,
9595
isPartialFilterExpression,
9696
ttl,
9797
wildcardProjection,
@@ -124,8 +124,8 @@ const rootReducer = (state, action) => {
124124
isBackground: IS_BACKGROUND_INITIAL_STATE,
125125
isUnique: IS_UNIQUE_INITIAL_STATE,
126126
isTtl: IS_TTL_INITIAL_STATE,
127-
isWildcard: IS_WILDCARD_INITIAL_STATE,
128-
isColumnstore: IS_COLUMNSTORE_INITIAL_STATE,
127+
hasWildcardProjection: HAS_WILDCARD_PROJECTION_INITIAL_STATE,
128+
hasColumnstoreProjection: HAS_COLUMNSTORE_PROJECTION_INITIAL_STATE,
129129
isPartialFilterExpression: IS_PARTIAL_FILTER_EXPRESSION_INITIAL_STATE,
130130
ttl: TTL_INITIAL_STATE,
131131
columnstoreProjection: COLUMNSTORE_PROJECTION_INITIAL_STATE,
@@ -179,15 +179,24 @@ export const createIndex = () => {
179179
return;
180180
}
181181
}
182-
if (state.isWildcard) {
182+
if (state.hasWildcardProjection) {
183183
try {
184184
options.wildcardProjection = EJSON.parse(state.wildcardProjection);
185185
} catch (err) {
186186
dispatch(handleError(`Bad WildcardProjection: ${String(err)}`));
187187
return;
188188
}
189189
}
190-
if (state.isColumnstore) {
190+
191+
const hasColumnstoreIndex = state.fields.some(
192+
(field) => field.type === 'columnstore'
193+
);
194+
if (hasColumnstoreIndex) {
195+
// Index type 'columnstore' does not support the 'unique' option.
196+
delete options.unique;
197+
}
198+
199+
if (state.hasColumnstoreProjection) {
191200
try {
192201
options.columnstoreProjection = EJSON.parse(
193202
state.columnstoreProjection
@@ -216,8 +225,9 @@ export const createIndex = () => {
216225
background: state.isBackground,
217226
unique: state.isUnique,
218227
ttl: state.isTtl,
219-
columnstore: state.isColumnstore,
220-
wildcard: state.isWildcard,
228+
columnstore_index: hasColumnstoreIndex,
229+
has_columnstore_projection: state.hasColumnstoreProjection,
230+
has_wildcard_projection: state.hasWildcardProjection,
221231
custom_collation: state.isCustomCollation,
222232
geo:
223233
state.fields.filter(({ type }) => type === '2dsphere').length > 0,
@@ -232,8 +242,9 @@ export const createIndex = () => {
232242
isPartialFilterExpression: state.isPartialFilterExpression,
233243
isTTL: state.isTtl,
234244
isUnique: state.isUnique,
235-
isColumnstore: state.isColumnstore,
236-
isWildcard: state.isWildcard,
245+
hasColumnstoreIndex,
246+
hasColumnstoreProjection: state.hasColumnstoreProjection,
247+
hasWildcardProjection: state.hasWildcardProjection,
237248
collation: state.collation,
238249
ttl: state.ttl,
239250
})

0 commit comments

Comments
 (0)