|
| 1 | +import type {TEvDescribeSchemeResult} from '../../../../../types/api/schema'; |
| 2 | +import {EPathType} from '../../../../../types/api/schema'; |
| 3 | +import {prepareSchemaData, prepareViewSchema} from '../prepareData'; |
| 4 | + |
| 5 | +describe('prepareSchemaData', () => { |
| 6 | + it('correctly parses row table data', () => { |
| 7 | + const data: TEvDescribeSchemeResult = { |
| 8 | + PathDescription: { |
| 9 | + Table: { |
| 10 | + Name: 'my_row_table', |
| 11 | + Columns: [ |
| 12 | + { |
| 13 | + Name: 'id', |
| 14 | + Type: 'Uint64', |
| 15 | + TypeId: 4, |
| 16 | + Id: 1, |
| 17 | + Family: 0, |
| 18 | + FamilyName: 'default', |
| 19 | + NotNull: false, |
| 20 | + }, |
| 21 | + { |
| 22 | + Name: 'category_id', |
| 23 | + Type: 'Uint64', |
| 24 | + TypeId: 4, |
| 25 | + Id: 2, |
| 26 | + Family: 0, |
| 27 | + FamilyName: 'default', |
| 28 | + NotNull: true, |
| 29 | + }, |
| 30 | + { |
| 31 | + Name: 'name', |
| 32 | + Type: 'Utf8', |
| 33 | + TypeId: 4608, |
| 34 | + Id: 3, |
| 35 | + Family: 0, |
| 36 | + FamilyName: 'default', |
| 37 | + DefaultFromLiteral: { |
| 38 | + type: { |
| 39 | + type_id: 'UTF8', |
| 40 | + }, |
| 41 | + value: { |
| 42 | + text_value: 'Ivan', |
| 43 | + }, |
| 44 | + }, |
| 45 | + NotNull: true, |
| 46 | + }, |
| 47 | + { |
| 48 | + Name: 'updated_on', |
| 49 | + Type: 'Datetime', |
| 50 | + TypeId: 49, |
| 51 | + Id: 4, |
| 52 | + Family: 0, |
| 53 | + FamilyName: 'default', |
| 54 | + NotNull: false, |
| 55 | + }, |
| 56 | + ], |
| 57 | + KeyColumnNames: ['category_id', 'name', 'id'], |
| 58 | + KeyColumnIds: [2, 3, 1], |
| 59 | + PartitionConfig: { |
| 60 | + ColumnFamilies: [ |
| 61 | + { |
| 62 | + Id: 0, |
| 63 | + StorageConfig: { |
| 64 | + SysLog: { |
| 65 | + PreferredPoolKind: 'ssd', |
| 66 | + }, |
| 67 | + Log: { |
| 68 | + PreferredPoolKind: 'ssd', |
| 69 | + }, |
| 70 | + Data: { |
| 71 | + PreferredPoolKind: 'ssd', |
| 72 | + }, |
| 73 | + }, |
| 74 | + }, |
| 75 | + ], |
| 76 | + }, |
| 77 | + }, |
| 78 | + }, |
| 79 | + }; |
| 80 | + |
| 81 | + const result = [ |
| 82 | + { |
| 83 | + id: 1, |
| 84 | + name: 'id', |
| 85 | + keyColumnIndex: 2, |
| 86 | + type: 'Uint64', |
| 87 | + notNull: false, |
| 88 | + autoIncrement: false, |
| 89 | + defaultValue: '-', |
| 90 | + familyName: undefined, |
| 91 | + prefferedPoolKind: undefined, |
| 92 | + columnCodec: undefined, |
| 93 | + }, |
| 94 | + { |
| 95 | + id: 2, |
| 96 | + name: 'category_id', |
| 97 | + keyColumnIndex: 0, |
| 98 | + type: 'Uint64', |
| 99 | + notNull: true, |
| 100 | + autoIncrement: false, |
| 101 | + defaultValue: '-', |
| 102 | + familyName: undefined, |
| 103 | + prefferedPoolKind: undefined, |
| 104 | + columnCodec: undefined, |
| 105 | + }, |
| 106 | + { |
| 107 | + id: 3, |
| 108 | + name: 'name', |
| 109 | + keyColumnIndex: 1, |
| 110 | + type: 'Utf8', |
| 111 | + notNull: true, |
| 112 | + autoIncrement: false, |
| 113 | + defaultValue: 'Ivan', |
| 114 | + familyName: undefined, |
| 115 | + prefferedPoolKind: undefined, |
| 116 | + columnCodec: undefined, |
| 117 | + }, |
| 118 | + { |
| 119 | + id: 4, |
| 120 | + name: 'updated_on', |
| 121 | + keyColumnIndex: -1, |
| 122 | + type: 'Datetime', |
| 123 | + notNull: false, |
| 124 | + autoIncrement: false, |
| 125 | + defaultValue: '-', |
| 126 | + familyName: undefined, |
| 127 | + prefferedPoolKind: undefined, |
| 128 | + columnCodec: undefined, |
| 129 | + }, |
| 130 | + ]; |
| 131 | + |
| 132 | + expect(prepareSchemaData(EPathType.EPathTypeTable, data)).toEqual(result); |
| 133 | + }); |
| 134 | + it('correctly parses column table data', () => { |
| 135 | + const data: TEvDescribeSchemeResult = { |
| 136 | + PathDescription: { |
| 137 | + ColumnTableDescription: { |
| 138 | + Name: 'my_column_table', |
| 139 | + Schema: { |
| 140 | + Columns: [ |
| 141 | + { |
| 142 | + Id: 1, |
| 143 | + Name: 'title', |
| 144 | + Type: 'Utf8', |
| 145 | + TypeId: 4608, |
| 146 | + NotNull: true, |
| 147 | + StorageId: '', |
| 148 | + DefaultValue: {}, |
| 149 | + ColumnFamilyId: 0, |
| 150 | + }, |
| 151 | + { |
| 152 | + Id: 2, |
| 153 | + Name: 'author', |
| 154 | + Type: 'Utf8', |
| 155 | + TypeId: 4608, |
| 156 | + NotNull: true, |
| 157 | + StorageId: '', |
| 158 | + DefaultValue: {}, |
| 159 | + ColumnFamilyId: 0, |
| 160 | + }, |
| 161 | + { |
| 162 | + Id: 3, |
| 163 | + Name: 'id', |
| 164 | + Type: 'Int64', |
| 165 | + TypeId: 3, |
| 166 | + NotNull: true, |
| 167 | + StorageId: '', |
| 168 | + DefaultValue: {}, |
| 169 | + ColumnFamilyId: 0, |
| 170 | + }, |
| 171 | + { |
| 172 | + Id: 4, |
| 173 | + Name: 'body', |
| 174 | + Type: 'Utf8', |
| 175 | + TypeId: 4608, |
| 176 | + NotNull: false, |
| 177 | + StorageId: '', |
| 178 | + DefaultValue: {}, |
| 179 | + ColumnFamilyId: 0, |
| 180 | + }, |
| 181 | + ], |
| 182 | + KeyColumnNames: ['author', 'title', 'id'], |
| 183 | + Version: '1', |
| 184 | + Options: { |
| 185 | + SchemeNeedActualization: false, |
| 186 | + }, |
| 187 | + ColumnFamilies: [ |
| 188 | + { |
| 189 | + Id: 0, |
| 190 | + Name: 'default', |
| 191 | + }, |
| 192 | + ], |
| 193 | + }, |
| 194 | + ColumnShardCount: 64, |
| 195 | + Sharding: { |
| 196 | + ColumnShards: ['72075186224107692'], |
| 197 | + HashSharding: { |
| 198 | + Function: 'HASH_FUNCTION_CONSISTENCY_64', |
| 199 | + Columns: ['id', 'author', 'title'], |
| 200 | + }, |
| 201 | + }, |
| 202 | + StorageConfig: { |
| 203 | + DataChannelCount: 64, |
| 204 | + }, |
| 205 | + }, |
| 206 | + }, |
| 207 | + }; |
| 208 | + const result = [ |
| 209 | + { |
| 210 | + id: 1, |
| 211 | + name: 'title', |
| 212 | + keyColumnIndex: 1, |
| 213 | + partitioningColumnIndex: 2, |
| 214 | + type: 'Utf8', |
| 215 | + notNull: true, |
| 216 | + }, |
| 217 | + { |
| 218 | + id: 2, |
| 219 | + name: 'author', |
| 220 | + keyColumnIndex: 0, |
| 221 | + partitioningColumnIndex: 1, |
| 222 | + type: 'Utf8', |
| 223 | + notNull: true, |
| 224 | + }, |
| 225 | + { |
| 226 | + id: 3, |
| 227 | + name: 'id', |
| 228 | + keyColumnIndex: 2, |
| 229 | + partitioningColumnIndex: 0, |
| 230 | + type: 'Int64', |
| 231 | + notNull: true, |
| 232 | + }, |
| 233 | + { |
| 234 | + id: 4, |
| 235 | + name: 'body', |
| 236 | + keyColumnIndex: -1, |
| 237 | + partitioningColumnIndex: -1, |
| 238 | + type: 'Utf8', |
| 239 | + notNull: false, |
| 240 | + }, |
| 241 | + ]; |
| 242 | + expect(prepareSchemaData(EPathType.EPathTypeColumnTable, data)).toEqual(result); |
| 243 | + }); |
| 244 | + it('returns empty array if data is undefined, empty or null', () => { |
| 245 | + expect(prepareSchemaData(EPathType.EPathTypeTable, {})).toEqual([]); |
| 246 | + expect(prepareSchemaData(EPathType.EPathTypeTable, undefined)).toEqual([]); |
| 247 | + expect(prepareSchemaData(EPathType.EPathTypeTable, null)).toEqual([]); |
| 248 | + }); |
| 249 | +}); |
| 250 | + |
| 251 | +describe('prepareViewSchema', () => { |
| 252 | + it('correctly parses data', () => { |
| 253 | + const data = [ |
| 254 | + {name: 'cost', type: 'Int32'}, |
| 255 | + {name: 'id', type: 'Int32'}, |
| 256 | + {name: 'price', type: 'Double'}, |
| 257 | + {name: 'value', type: 'Utf8?'}, |
| 258 | + ]; |
| 259 | + const result = [ |
| 260 | + {type: 'Int32', name: 'cost'}, |
| 261 | + {type: 'Int32', name: 'id'}, |
| 262 | + {type: 'Double', name: 'price'}, |
| 263 | + {type: 'Utf8', name: 'value'}, |
| 264 | + ]; |
| 265 | + |
| 266 | + expect(prepareViewSchema(data)).toEqual(result); |
| 267 | + }); |
| 268 | + it('returns empty array if data is undefined or empty', () => { |
| 269 | + expect(prepareViewSchema()).toEqual([]); |
| 270 | + expect(prepareViewSchema([])).toEqual([]); |
| 271 | + }); |
| 272 | +}); |
0 commit comments