public void deParse(CreateTable createTable) { buffer.append("CREATE TABLE ").append(createTable.getTable().getFullyQualifiedName()); if (createTable.getColumnDefinitions() != null) { buffer.append(" ("); for (Iterator<ColumnDefinition> iter = createTable.getColumnDefinitions().iterator(); iter.hasNext(); ) { ColumnDefinition columnDefinition = iter.next(); buffer.append(columnDefinition.getColumnName()); buffer.append(" "); buffer.append(columnDefinition.getColDataType().toString()); if (columnDefinition.getColumnSpecStrings() != null) { for (String s : columnDefinition.getColumnSpecStrings()) { buffer.append(" "); buffer.append(s); } } if (iter.hasNext()) { buffer.append(", "); } } if (createTable.getIndexes() != null) { for (Iterator<Index> iter = createTable.getIndexes().iterator(); iter.hasNext(); ) { buffer.append(", "); Index index = iter.next(); buffer.append(index.toString()); } } buffer.append(")"); } }
@SuppressWarnings("deprecation") @Override public void serialize(SerializerOutput out, ValueContainer value) throws IOException { out.writeInt(value.count); for (ArrayList<Datum> tuple : value.tuples) { int index = -1; for (ColumnDefinition datumType : colsDef) { if (datumType.getColDataType().getDataType().equalsIgnoreCase("long") || datumType.getColDataType().getDataType().equalsIgnoreCase("int") || datumType.getColDataType().getDataType().equalsIgnoreCase("number") || datumType.getColDataType().getDataType().equalsIgnoreCase("integer")) { out.writeLong((long) tuple.get(++index).getValue()); } else if (datumType.getColDataType().getDataType().equalsIgnoreCase("double") || datumType.getColDataType().getDataType().equalsIgnoreCase("float") || datumType.getColDataType().getDataType().equalsIgnoreCase("decimal")) { out.writeDouble((double) tuple.get(++index).getValue()); } else if (datumType.getColDataType().getDataType().equalsIgnoreCase("date")) { index++; out.writeInt(((Date) (tuple.get(index).getValue())).getYear()); out.writeInt(((Date) (tuple.get(index).getValue())).getMonth()); out.writeInt(((Date) (tuple.get(index).getValue())).getDate()); } else { out.writeUTF(tuple.get(++index).getValue().toString()); } } } }
@Override public ValueContainer deserialize(SerializerInput in) throws IOException, ClassNotFoundException { ArrayList<ArrayList<Datum>> tuples = new ArrayList<ArrayList<Datum>>(); int count = in.readInt(); for (int i = 0; i < count; i++) { ArrayList<Datum> tuple = new ArrayList<Datum>(); for (ColumnDefinition datumType : colsDef) { if (datumType.getColDataType().getDataType().equalsIgnoreCase("long") || datumType.getColDataType().getDataType().equalsIgnoreCase("int") || datumType.getColDataType().getDataType().equalsIgnoreCase("number") || datumType.getColDataType().getDataType().equalsIgnoreCase("integer")) { tuple.add(new Datum.DatumLong(in.readLong())); } else if (datumType.getColDataType().getDataType().equalsIgnoreCase("double") || datumType.getColDataType().getDataType().equalsIgnoreCase("float") || datumType.getColDataType().getDataType().equalsIgnoreCase("decimal")) { tuple.add(new Datum.DatumDouble(in.readDouble())); } else if (datumType.getColDataType().getDataType().equalsIgnoreCase("date")) { @SuppressWarnings("deprecation") Date date = new Date(in.readInt(), in.readInt(), in.readInt()); tuple.add(new Datum.DatumDate(date)); } else { tuple.add(new Datum.DatumString(in.readUTF())); } } tuples.add(tuple); } ValueContainer value = new ValueContainer(tuples); return value; }
public boolean checkSchema( ArrayList<ColumnDefinition> parentSchema, ArrayList<ColumnDefinition> childSchema) { int flag = 0; /*if(parentSchema==null) return false; if(childSchema==null) return false;*/ for (ColumnDefinition parentColDef : parentSchema) { flag = 0; for (ColumnDefinition childColDef : childSchema) { if (parentColDef .getColumnName() .toUpperCase() .equals(childColDef.getColumnName().toUpperCase())) flag = 1; } if (flag == 0) return false; } return true; }