Skip to content

Commit

Permalink
[FLINK-10116] [types] Fix getTotalFields() implementation of some Typ…
Browse files Browse the repository at this point in the history
…eInfos.

This closes apache#6569.
  • Loading branch information
fhueske committed Aug 16, 2018
1 parent b34ee94 commit 3390164
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public int getArity() {
@Override
@PublicEvolving
public int getTotalFields() {
return 0;
return 1;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public abstract class TypeInformation<T> implements Serializable {
* fields, in the case of composite types. In the example below, the OuterType type has three
* fields in total.
*
* <p>The total number of fields must be at least 1.
*
* @return The number of fields in this type, including its sub-fields (for composite types)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ public void testSerialization() {
}
}

@Test
public void testGetTotalFields() {
final T[] testData = getTestData();
for (T typeInfo : testData) {
assertTrue(
"Number of total fields must be at least 1",
typeInfo.getTotalFields() > 0);
}
}

private static class UnrelatedTypeInfo extends TypeInformation<Object> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ protected MissingTypeInfo[] getTestData() {
public void testSerialization() {
// this class is not intended to be serialized
}

@Override
public void testGetTotalFields() {
// getTotalFields is not meant to be called
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public int getArity() {

@Override
public int getTotalFields() {
return 0;
return 1;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public int getArity() {

@Override
public int getTotalFields() {
return 0;
return 1;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public int getArity() {
@Override
@PublicEvolving
public int getTotalFields() {
return 0;
return 1;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ScalaNothingTypeInfo extends TypeInformation[Nothing] {
@PublicEvolving
override def getArity: Int = 0
@PublicEvolving
override def getTotalFields: Int = 0
override def getTotalFields: Int = 1
@PublicEvolving
override def getTypeClass: Class[Nothing] = classOf[Nothing]
@PublicEvolving
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class UnitTypeInfo extends TypeInformation[Unit] {
@PublicEvolving
override def getArity(): Int = 0
@PublicEvolving
override def getTotalFields(): Int = 0
override def getTotalFields(): Int = 1
@PublicEvolving
override def getTypeClass(): Class[Unit] = classOf[Unit]
@PublicEvolving
Expand Down

0 comments on commit 3390164

Please sign in to comment.