Schema implements ProtoObject<SchemaProto>, Cloneable, GsonObject { public synchronized Schema addColumn(String name, TypeDesc typeDesc) { String normalized = name; if(fieldsByQualifiedName.containsKey(normalized)) { LOG.error("Already exists column " + normalized); throw new AlreadyExistsFieldException(normalized); } Column newCol = new Column(normalized, typeDesc); fields.add(newCol); fieldsByQualifiedName.put(newCol.getQualifiedName(), fields.size() - 1); fieldsByName.put(newCol.getSimpleName(), TUtil.newList(fields.size() - 1)); return this; } Schema();  Schema(SchemaProto proto);  Schema(Schema schema);  Schema(Column [] columns);  Schema(Iterable<Column> columns); void setQualifier(String qualifier); int size(); Column getColumn(int id); Column getColumn(Column column); int getIndex(Column column); Column getColumn(String name); int getColumnId(String name); int getColumnIdByName(String colName); List<Column> getRootColumns(); List<Column> getAllColumns(); boolean contains(String name); boolean contains(Column column); boolean containsByQualifiedName(String qualifiedName); boolean containsByName(String colName); boolean containsAll(Collection<Column> columns); synchronized Schema addColumn(String name, TypeDesc typeDesc); synchronized Schema addColumn(String name, Type type); synchronized Schema addColumn(String name, Type type, int length); synchronized Schema addColumn(String name, DataType dataType); synchronized void addColumn(Column column); synchronized void addColumns(Schema schema); @Override int hashCode(); @Override boolean equals(Object o); @Override Object clone(); @Override SchemaProto getProto(); String toString(); @Override String toJson(); Column [] toArray();  }
@Test public final void testEqualsObject() { Schema schema2 = new Schema(); schema2.addColumn("name", Type.TEXT); schema2.addColumn("age", Type.INT4); schema2.addColumn("addr", Type.TEXT); assertEquals(schema, schema2); }
@Test(expected = AlreadyExistsFieldException.class) public final void testAddExistColumn() { Schema schema = new Schema(); schema.addColumn("abc", Type.FLOAT8); schema.addColumn("bbc", Type.FLOAT8); schema.addColumn("abc", Type.INT4); }
@Test public void testNestedRecord4() { Schema root = new Schema(); Schema nf2DotNf1 = new Schema(); nf2DotNf1.addColumn("f1", Type.INT8); nf2DotNf1.addColumn("f2", Type.INT8); Schema nf2DotNf2 = new Schema(); nf2DotNf2.addColumn("f1", Type.INT8); nf2DotNf2.addColumn("f2", Type.INT8); Schema nf2 = new Schema(); nf2.addColumn("f1", Type.INT8); nf2.addColumn("nf1", new TypeDesc(nf2DotNf1)); nf2.addColumn("nf2", new TypeDesc(nf2DotNf2)); nf2.addColumn("f2", Type.INT8); root.addColumn("f1", Type.INT8); root.addColumn("nf1", Type.INT8); root.addColumn("nf2", new TypeDesc(nf2)); root.addColumn("f2", Type.INT8); verifySchema(root); }