1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.types;
19
20 import org.apache.hadoop.hbase.classification.InterfaceAudience;
21 import org.apache.hadoop.hbase.classification.InterfaceStability;
22 import org.apache.hadoop.hbase.util.Order;
23 import org.apache.hadoop.hbase.util.PositionedByteRange;
24
25
26
27
28
29
30 @SuppressWarnings("unchecked")
31 @InterfaceAudience.Public
32 @InterfaceStability.Evolving
33 public abstract class Union2<A, B> implements DataType<Object> {
34
35 protected final DataType<A> typeA;
36 protected final DataType<B> typeB;
37
38
39
40
41
42 public Union2(DataType<A> typeA, DataType<B> typeB) {
43 this.typeA = typeA;
44 this.typeB = typeB;
45 }
46
47 @Override
48 public boolean isOrderPreserving() {
49 return typeA.isOrderPreserving() && typeB.isOrderPreserving();
50 }
51
52 @Override
53 public Order getOrder() { return null; }
54
55 @Override
56 public boolean isNullable() {
57 return typeA.isNullable() && typeB.isNullable();
58 }
59
60 @Override
61 public boolean isSkippable() {
62 return typeA.isSkippable() && typeB.isSkippable();
63 }
64
65 @Override
66 public Class<Object> encodedClass() {
67 throw new UnsupportedOperationException(
68 "Union types do not expose a definitive encoded class.");
69 }
70
71
72
73
74 public A decodeA(PositionedByteRange src) {
75 return (A) decode(src);
76 }
77
78
79
80
81 public B decodeB(PositionedByteRange src) {
82 return (B) decode(src);
83 }
84 }