@@ -298,72 +298,97 @@ performed). All types supporting metadata allow at least this style.
298
298
const COL_INFO = """
299
299
`col` must have a type that is supported by table `x` for column indexing.
300
300
Following the Tables.jl contract `Symbol` and `Int` are always allowed.
301
- Passing `col` that is not a column of `x` throws an error .
301
+ Throw an error if `col` is not a column of `x`.
302
302
"""
303
303
304
304
"""
305
- metadata(x, key::AbstractString; style::Bool=false )
305
+ metadatasupport(T::Type )
306
306
307
- Return metadata value associated with object `x` for key `key`.
308
- If `x` does not support metadata throw `ArgumentError`.
309
- If `x` supports metadata, but does not have a mapping for `key` throw
310
- `KeyError`.
307
+ Return a `NamedTuple{(:read, :write), Tuple{Bool, Bool}}` indicating whether
308
+ values of type `T` support metadata.
309
+
310
+ The `read` field indicates whether reading metadata with the [`metadata`](@ref)
311
+ and [`metadatakeys`]](@ref) functions is supported.
312
+
313
+ The `write` field indicates whether modifying metadata with the [`metadata!`](@ref),
314
+ [`deletemetadata!`](@ref), and [`emptymetadata!`](@ref) functions is supported.
315
+ """
316
+ metadatasupport (:: Type ) = (read= false , write= false )
317
+
318
+ """
319
+ colmetadatasupport(T::Type)
320
+
321
+ Return a `NamedTuple{(:read, :write), Tuple{Bool, Bool}}` indicating whether
322
+ values of type `T` support column metadata.
323
+
324
+ The `read` field indicates whether reading metadata with the [`colmetadata`](@ref)
325
+ and [`colmetadatakeys`](@ref) functions is supported.
326
+
327
+ The `write` field indicates whether modifying metadata with the [`colmetadata!`](@ref),
328
+ [`deletecolmetadata!`](@ref), and [`emptycolmetadata!`](@ref) functions is supported.
329
+ """
330
+ colmetadatasupport (:: Type ) = (read= false , write= false )
331
+
332
+ """
333
+ metadata(x, key::AbstractString, [default]; style::Bool=false)
334
+
335
+ Return metadata value associated with object `x` for key `key`. Throw an error
336
+ if `x` does not support reading metadata or does not have a mapping for `key`.
311
337
312
338
If `style=true` return a tuple of metadata value and metadata style. Metadata
313
- style is an additional information about the kind of metadata that is stored
314
- for the `key`.
339
+ style is an additional information about the kind of metadata that is stored for
340
+ the `key`.
315
341
316
342
$STYLE_INFO
343
+
344
+ If `default` is passed then return it if reading metadata is supported but
345
+ mapping for `key` is missing. If `style=true` return `(default, :default)`.
317
346
"""
318
- metadata (:: T , :: AbstractString ; style:: Bool = false ) where {T} =
319
- throw (ArgumentError (" Objects of type $T do not support getting metadata" ))
347
+ function metadata end
320
348
321
349
"""
322
350
metadatakeys(x)
323
351
324
352
Return an iterator of metadata keys for which `metadata(x, key)` returns a
325
- metadata value. If `x` does not support metadata return `()`.
353
+ metadata value.
354
+ Throw an error if `x` does not support reading metadata.
326
355
"""
327
- metadatakeys ( :: Any ) = ()
356
+ function metadatakeys end
328
357
329
358
"""
330
359
metadata!(x, key::AbstractString, value; style)
331
360
332
361
Set metadata for object `x` for key `key` to have value `value`
333
362
and style `style` and return `x`.
334
- If `x` does not support setting metadata throw `ArgumentError` .
363
+ Throw an error if `x` does not support setting metadata.
335
364
336
365
$STYLE_INFO
337
366
"""
338
- metadata! (:: T , :: AbstractString , :: Any ; style) where {T} =
339
- throw (ArgumentError (" Objects of type $T do not support setting metadata" ))
367
+ function metadata! end
340
368
341
369
"""
342
370
deletemetadata!(x, key::AbstractString)
343
371
344
372
Delete metadata for object `x` for key `key` and return `x`
345
373
(if metadata for `key` is not present do not perform any action).
346
- If `x` does not support metadata deletion throw `ArgumentError` .
374
+ Throw an error if `x` does not support metadata deletion.
347
375
"""
348
- deletemetadata! (:: T , :: AbstractString ) where {T} =
349
- throw (ArgumentError (" Objects of type $T do not support metadata deletion" ))
376
+ function deletemetadata! end
350
377
351
378
"""
352
379
emptymetadata!(x)
353
380
354
381
Delete all metadata for object `x`.
355
- If `x` does not support metadata deletion throw `ArgumentError` .
382
+ Throw an error if `x` does not support metadata deletion.
356
383
"""
357
- emptymetadata! (:: T ) where {T} =
358
- throw (ArgumentError (" Objects of type $T do not support metadata deletion" ))
384
+ function emptymetadata! end
359
385
360
386
"""
361
- colmetadata(x, col, key::AbstractString; style::Bool=false)
387
+ colmetadata(x, col, key::AbstractString, [default] ; style::Bool=false)
362
388
363
389
Return metadata value associated with table `x` for column `col` and key `key`.
364
- If `x` does not support metadata for column `col` throw `ArgumentError`. If `x`
365
- supports metadata, but does not have a mapping for column `col` for `key` throw
366
- `KeyError`.
390
+ Throw an error if `x` does not support reading metadata for column `col` or `x`
391
+ supports reading metadata, but does not have a mapping for column `col` for `key`.
367
392
368
393
$COL_INFO
369
394
@@ -372,73 +397,58 @@ style is an additional information about the kind of metadata that is stored for
372
397
the `key`.
373
398
374
399
$STYLE_INFO
400
+
401
+ If `default` is passed then return it if `x` supports reading metadata and has
402
+ column `col` but mapping for `key` is missing.
403
+ If `style=true` return `(default, :default)`.
375
404
"""
376
- colmetadata (:: T , :: Int , :: AbstractString ; style:: Bool = false ) where {T} =
377
- throw (ArgumentError (" Objects of type $T do not support getting column metadata" ))
378
- colmetadata (:: T , :: Symbol , :: AbstractString ; style:: Bool = false ) where {T} =
379
- throw (ArgumentError (" Objects of type $T do not support getting column metadata" ))
405
+ function colmetadata end
380
406
381
407
"""
382
408
colmetadatakeys(x, [col])
383
409
384
- If `col` is passed return an iterator of metadata keys for which `metadata(x,
385
- col, key)` returns a metadata value. If `x` does not support metadata for column
386
- `col` return `() `.
410
+ If `col` is passed return an iterator of metadata keys for which
411
+ `metadata(x, col, key)` returns a metadata value. Throw an error if `x` does not
412
+ support reading column metadata or if `col` is not a column of `x `.
387
413
388
414
`col` must have a type that is supported by table `x` for column indexing.
389
- Following the Tables.jl contract `Symbol` and `Int` are always allowed. Passing
390
- `col` that is not a column of `x` either throws an error (this is a
391
- preferred behavior if it is possible) or returns `()` (this duality is allowed
392
- as some Tables.jl tables do not have a schema).
415
+ Following the Tables.jl contract `Symbol` and `Int` are always allowed.
393
416
394
417
If `col` is not passed return an iterator of `col => colmetadatakeys(x, col)`
395
418
pairs for all columns that have metadata, where `col` are `Symbol`.
396
419
If `x` does not support column metadata return `()`.
397
420
"""
398
- colmetadatakeys (:: Any , :: Int ) = ()
399
- colmetadatakeys (:: Any , :: Symbol ) = ()
400
- colmetadatakeys (:: Any ) = ()
421
+ function colmetadatakeys end
401
422
402
423
"""
403
424
colmetadata!(x, col, key::AbstractString, value; style)
404
425
405
426
Set metadata for table `x` for column `col` for key `key` to have value `value`
406
427
and style `style` and return `x`.
407
- If `x` does not support setting metadata for column `col` throw `ArgumentError `.
428
+ Throw an error if `x` does not support setting metadata for column `col`.
408
429
409
430
$COL_INFO
410
431
411
432
$STYLE_INFO
412
433
"""
413
- colmetadata! (:: T , :: Int , :: AbstractString , :: Any ; style) where {T} =
414
- throw (ArgumentError (" Objects of type $T do not support setting metadata" ))
415
- colmetadata! (:: T , :: Symbol , :: AbstractString , :: Any ; style) where {T} =
416
- throw (ArgumentError (" Objects of type $T do not support setting metadata" ))
434
+ function colmetadata! end
417
435
418
436
"""
419
437
deletecolmetadata!(x, col, key::AbstractString)
420
438
421
439
Delete metadata for table `x` for column `col` for key `key` and return `x`
422
440
(if metadata for `key` is not present do not perform any action).
423
- If `x` does not support metadata deletion for column `col` throw `ArgumentError `.
441
+ Throw an error if `x` does not support metadata deletion for column `col`.
424
442
"""
425
- deletecolmetadata! (:: T , :: Symbol , :: AbstractString ) where {T} =
426
- throw (ArgumentError (" Objects of type $T do not support metadata deletion" ))
427
- deletecolmetadata! (:: T , :: Int , :: AbstractString ) where {T} =
428
- throw (ArgumentError (" Objects of type $T do not support metadata deletion" ))
443
+ function deletecolmetadata! end
429
444
430
445
"""
431
446
emptycolmetadata!(x, [col])
432
447
433
448
Delete all metadata for table `x` for column `col`.
434
449
If `col` is not passed delete all column level metadata for table `x`.
435
- If `x` does not support metadata deletion for column `col` throw `ArgumentError`.
436
- """
437
- emptycolmetadata! (:: T , :: Symbol ) where {T} =
438
- throw (ArgumentError (" Objects of type $T do not support metadata deletion" ))
439
- emptycolmetadata! (:: T , :: Int ) where {T} =
440
- throw (ArgumentError (" Objects of type $T do not support metadata deletion" ))
441
- emptycolmetadata! (:: T ) where {T} =
442
- throw (ArgumentError (" Objects of type $T do not support metadata deletion" ))
450
+ Throw an error if `x` does not support metadata deletion for column `col`.
451
+ """
452
+ function emptycolmetadata! end
443
453
444
454
end # module
0 commit comments