Java Code Examples for com.amazonaws.services.dynamodbv2.model.AttributeValue#getNS()

The following examples show how to use com.amazonaws.services.dynamodbv2.model.AttributeValue#getNS() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Util.java    From syndesis with Apache License 2.0 6 votes vote down vote up
public static Object getValue(AttributeValue value) {
    if(value.getB() != null) {
        return value.getB();
    } else if (value.getS() != null){
        return value.getS();
    } else if (value.getBOOL() != null){
        return value.getBOOL();
    } else if (value.getBS() != null){
        return value.getBS();
    } else if (value.getL() != null){
        return value.getL();
    } else if (value.getM() != null){
        return value.getM();
    } else if (value.getN() != null){
        return value.getN();
    } else if (value.getNS() != null){
        return value.getNS();
    } else if (value.getSS() != null){
        return value.getSS();
    }
    return null;
}
 
Example 2
Source File: ImmutableAttributeValue.java    From dynamodb-transactions with Apache License 2.0 6 votes vote down vote up
public ImmutableAttributeValue(AttributeValue av) {
    s = av.getS();
    n = av.getN();
    b = av.getB() != null ? av.getB().array().clone() : null;
    ns = av.getNS() != null ? new ArrayList<String>(av.getNS()) : null;
    ss = av.getSS() != null ? new ArrayList<String>(av.getSS()) : null;
    bs = av.getBS() != null ? new ArrayList<byte[]>(av.getBS().size()) : null;
    
    if(av.getBS() != null) {
        for(ByteBuffer buf : av.getBS()) {
            if(buf != null) {
                bs.add(buf.array().clone());
            } else {
                bs.add(null);
            }
        }
    }
}
 
Example 3
Source File: DynamoDBTableReplicator.java    From podyn with Apache License 2.0 6 votes vote down vote up
public static TableColumnType columnTypeFromDynamoValue(AttributeValue typedValue) {
	if(typedValue.getB() != null) {
		return TableColumnType.bytea;
	} else if (typedValue.getBOOL() != null) {
		return TableColumnType.bool;
	} else if (typedValue.getBS() != null) {
		return TableColumnType.jsonb;
	} else if (typedValue.getL() != null) {
		return TableColumnType.jsonb;
	} else if (typedValue.getM() != null) {
		return TableColumnType.jsonb;
	} else if (typedValue.getN() != null) {
		return TableColumnType.numeric;
	} else if (typedValue.getNS() != null) {
		return TableColumnType.jsonb;
	} else if (typedValue.getS() != null) {
		return TableColumnType.text;
	} else if (typedValue.getSS() != null) {
		return TableColumnType.jsonb;
	} else {
		return TableColumnType.text;
	}
}
 
Example 4
Source File: AttributeValueCoder.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public void encode(AttributeValue value, OutputStream outStream) throws IOException {

  if (value.getS() != null) {
    StringUtf8Coder.of().encode(AttributeValueType.s.toString(), outStream);
    StringUtf8Coder.of().encode(value.getS(), outStream);
  } else if (value.getN() != null) {
    StringUtf8Coder.of().encode(AttributeValueType.n.toString(), outStream);
    StringUtf8Coder.of().encode(value.getN(), outStream);
  } else if (value.getBOOL() != null) {
    StringUtf8Coder.of().encode(AttributeValueType.bOOL.toString(), outStream);
    BooleanCoder.of().encode(value.getBOOL(), outStream);
  } else if (value.getB() != null) {
    StringUtf8Coder.of().encode(AttributeValueType.b.toString(), outStream);
    ByteArrayCoder.of().encode(convertToByteArray(value.getB()), outStream);
  } else if (value.getSS() != null) {
    StringUtf8Coder.of().encode(AttributeValueType.sS.toString(), outStream);
    LIST_STRING_CODER.encode(value.getSS(), outStream);
  } else if (value.getNS() != null) {
    StringUtf8Coder.of().encode(AttributeValueType.nS.toString(), outStream);
    LIST_STRING_CODER.encode(value.getNS(), outStream);
  } else if (value.getBS() != null) {
    StringUtf8Coder.of().encode(AttributeValueType.bS.toString(), outStream);
    LIST_BYTE_CODER.encode(convertToListByteArray(value.getBS()), outStream);
  } else if (value.getL() != null) {
    StringUtf8Coder.of().encode(AttributeValueType.l.toString(), outStream);
    LIST_ATTRIBUTE_CODER.encode(value.getL(), outStream);
  } else if (value.getM() != null) {
    StringUtf8Coder.of().encode(AttributeValueType.m.toString(), outStream);
    MAP_ATTRIBUTE_CODER.encode(value.getM(), outStream);
  } else if (value.getNULL() != null) {
    StringUtf8Coder.of().encode(AttributeValueType.nULLValue.toString(), outStream);
    BooleanCoder.of().encode(value.getNULL(), outStream);
  } else {
    throw new CoderException("Unknown Type");
  }
}
 
Example 5
Source File: DynamoDBUnmarshallerUtil.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
public static NSUnmarshaller getDoubleNSUnmarshaller() {
    return new NSUnmarshaller() {
        @Override
        public Object unmarshall(final AttributeValue value) {
            final Set<Double> argument = new HashSet<Double>();
            for (final String s : value.getNS()) {
                argument.add(Double.parseDouble(s));
            }
            return argument;
        }
    };
}
 
Example 6
Source File: DynamoDBUnmarshallerUtil.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
public static NSUnmarshaller getBigDecimalNSUnmarshaller() {
    return new NSUnmarshaller() {

        @Override
        public Object unmarshall(final AttributeValue value) {
            final Set<BigDecimal> argument = new HashSet<BigDecimal>();
            for (final String s : value.getNS()) {
                argument.add(new BigDecimal(s));
            }
            return argument;
        }
    };
}
 
Example 7
Source File: DynamoDBUnmarshallerUtil.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
public static NSUnmarshaller getBigIntegerNSUnmarshaller() {
    return new NSUnmarshaller() {

        @Override
        public Object unmarshall(final AttributeValue value) {
            final Set<BigInteger> argument = new HashSet<BigInteger>();
            for (final String s : value.getNS()) {
                argument.add(new BigInteger(s));
            }
            return argument;
        }
    };
}
 
Example 8
Source File: DynamoDBUnmarshallerUtil.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
public static NSUnmarshaller getIntegerNSUnmarshaller() {
    return new NSUnmarshaller() {

        @Override
        public Object unmarshall(final AttributeValue value) {
            final Set<Integer> argument = new HashSet<Integer>();
            for (final String s : value.getNS()) {
                argument.add(Integer.parseInt(s));
            }
            return argument;
        }
    };
}
 
Example 9
Source File: DynamoDBUnmarshallerUtil.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
public static NSUnmarshaller getFloatNSUnmarshaller() {
    return new NSUnmarshaller() {

        @Override
        public Object unmarshall(final AttributeValue value) {
            final Set<Float> argument = new HashSet<Float>();
            for (final String s : value.getNS()) {
                argument.add(Float.parseFloat(s));
            }
            return argument;
        }
    };
}
 
Example 10
Source File: DynamoDBUnmarshallerUtil.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
public static NSUnmarshaller getByteNSUnmarshaller() {
    return new NSUnmarshaller() {

        @Override
        public Object unmarshall(final AttributeValue value) {
            final Set<Byte> argument = new HashSet<Byte>();
            for (final String s : value.getNS()) {
                argument.add(Byte.parseByte(s));
            }
            return argument;
        }
    };
}
 
Example 11
Source File: DynamoDBUnmarshallerUtil.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
public static NSUnmarshaller getLongNSUnmarshaller() {
    return new NSUnmarshaller() {

        @Override
        public Object unmarshall(final AttributeValue value) {
            final Set<Long> argument = new HashSet<Long>();
            for (final String s : value.getNS()) {
                argument.add(Long.parseLong(s));
            }
            return argument;
        }
    };
}
 
Example 12
Source File: DynamoDBUnmarshallerUtil.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
public static NSUnmarshaller getShortNSUnmarshaller() {
    return new NSUnmarshaller() {

        @Override
        public Object unmarshall(final AttributeValue value) {
            final Set<Short> argument = new HashSet<Short>();
            for (final String s : value.getNS()) {
                argument.add(Short.parseShort(s));
            }
            return argument;
        }
    };
}
 
Example 13
Source File: DynamoDBUnmarshallerUtil.java    From Cheddar with Apache License 2.0 5 votes vote down vote up
public static NSUnmarshaller getBooleanNSUnmarshaller() {
    return new NSUnmarshaller() {

        @Override
        public Object unmarshall(final AttributeValue value) {
            final Set<Boolean> argument = new HashSet<Boolean>();
            for (final String s : value.getNS()) {
                argument.add(parseBoolean(s));
            }
            return argument;
        }
    };
}
 
Example 14
Source File: DynamoDb2Item.java    From JustJson with Apache License 2.0 5 votes vote down vote up
@Override
protected JsonElement to(AttributeValue value) {
    //the output JASON care only for one type of attribute.
    JsonElement el = new JsonString("");
    try {
        if(value.getS()!=null) {
            el = JsonElement.wrap(value.getS());
        } else if(value.getN()!=null) {
            el = JsonElement.wrap(value.getN());
        }
        else if(value.getSS()!=null) {
            el = JsonElement.wrap(value.getSS());
        }
        else if(value.getNS()!=null) {
            el = JsonElement.wrap(value.getNS());
        }
        else if(value.getB()!=null) {
            el = JsonElement.wrap(value.getB());
        }
        else if(value.getN()!=null) {
            el = JsonElement.wrap(value.getBS());
        }

    } catch (JsonException e) {
        e.printStackTrace();
    }
    return el;
}
 
Example 15
Source File: HiveDynamoDBNumberSetType.java    From emr-dynamodb-connector with Apache License 2.0 4 votes vote down vote up
@Override
public Object getHiveData(AttributeValue data, ObjectInspector objectInspector) {
  return data.getNS() == null ? null : DynamoDBDataParser.getNumberObjectList(data.getNS(), objectInspector);
}
 
Example 16
Source File: DynamoDbDelegate.java    From dynamodb-janusgraph-storage-backend with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method that can clone an Attribute Value
 *
 * @param val the AttributeValue to copy
 * @param sourceDestinationMap used to avoid loops by keeping track of references
 * @return a copy of val
 */
public static AttributeValue clone(final AttributeValue val, final IdentityHashMap<AttributeValue, AttributeValue> sourceDestinationMap) {
    if (val == null) {
        return null;
    }

    if (sourceDestinationMap.containsKey(val)) {
        return sourceDestinationMap.get(val);
    }

    final AttributeValue clonedVal = new AttributeValue();
    sourceDestinationMap.put(val, clonedVal);
    if (val.getN() != null) {
        clonedVal.setN(val.getN());
    } else if (val.getS() != null) {
        clonedVal.setS(val.getS());
    } else if (val.getB() != null) {
        clonedVal.setB(val.getB());
    } else if (val.getNS() != null) {
        clonedVal.setNS(val.getNS());
    } else if (val.getSS() != null) {
        clonedVal.setSS(val.getSS());
    } else if (val.getBS() != null) {
        clonedVal.setBS(val.getBS());
    } else if (val.getBOOL() != null) {
        clonedVal.setBOOL(val.getBOOL());
    } else if (val.getNULL() != null) {
        clonedVal.setNULL(val.getNULL());
    } else if (val.getL() != null) {
        final List<AttributeValue> list = new ArrayList<>(val.getL().size());
        for (AttributeValue listItemValue : val.getL()) {
            if (!sourceDestinationMap.containsKey(listItemValue)) {
                sourceDestinationMap.put(listItemValue, clone(listItemValue, sourceDestinationMap));
            }
            list.add(sourceDestinationMap.get(listItemValue));
        }
        clonedVal.setL(list);
    } else if (val.getM() != null) {
        final Map<String, AttributeValue> map = new HashMap<>(val.getM().size());
        for (Entry<String, AttributeValue> pair : val.getM().entrySet()) {
            if (!sourceDestinationMap.containsKey(pair.getValue())) {
                sourceDestinationMap.put(pair.getValue(), clone(pair.getValue(), sourceDestinationMap));
            }
            map.put(pair.getKey(), sourceDestinationMap.get(pair.getValue()));
        }
        clonedVal.setM(map);
    }
    return clonedVal;
}
 
Example 17
Source File: AttributeValueMarshaller.java    From aws-dynamodb-encryption-java with Apache License 2.0 4 votes vote down vote up
private static void marshall(final AttributeValue attributeValue, final DataOutputStream out)
        throws IOException {
    
    if (attributeValue.getB() != null) {
        out.writeChar('b');
        writeBytes(attributeValue.getB(), out);
    } else if (attributeValue.getBS() != null) {
        out.writeChar('B');
        writeBytesList(attributeValue.getBS(), out);
    } else if (attributeValue.getN() != null) {
        out.writeChar('n');
        writeString(trimZeros(attributeValue.getN()), out);
    } else if (attributeValue.getNS() != null) {
        out.writeChar('N');

        final List<String> ns = new ArrayList<String>(attributeValue.getNS().size());
        for (final String n : attributeValue.getNS()) {
            ns.add(trimZeros(n));
        }
        writeStringList(ns, out);
    } else if (attributeValue.getS() != null) {
        out.writeChar('s');
        writeString(attributeValue.getS(), out);
    } else if (attributeValue.getSS() != null) {
        out.writeChar('S');
        writeStringList(attributeValue.getSS(), out);
    } else if (attributeValue.getBOOL() != null) {
        out.writeChar('?');
        out.writeByte((attributeValue.getBOOL() ? TRUE_FLAG : FALSE_FLAG));
    } else if (Boolean.TRUE.equals(attributeValue.getNULL())) {
        out.writeChar('\0');
    } else if (attributeValue.getL() != null) {
        final List<AttributeValue> l = attributeValue.getL();
        out.writeChar('L');
        out.writeInt(l.size());
        for (final AttributeValue attr : l) {
            if (attr == null) {
                throw new NullPointerException(
                    "Encountered null list entry value while marshalling attribute value "
                    + attributeValue);
            }
            marshall(attr, out);
        }
    } else if (attributeValue.getM() != null) {
        final Map<String, AttributeValue> m = attributeValue.getM();
        final List<String> mKeys = new ArrayList<String>(m.keySet());
        Collections.sort(mKeys);
        out.writeChar('M');
        out.writeInt(m.size());
        for (final String mKey : mKeys) {
            marshall(new AttributeValue().withS(mKey), out);
            
            final AttributeValue mValue = m.get(mKey);
            
            if (mValue == null) {
                throw new NullPointerException(
                    "Encountered null map value for key "
                    + mKey
                    + " while marshalling attribute value "
                    + attributeValue);
            }
            marshall(mValue, out);
        }
    } else {
        throw new IllegalArgumentException("A seemingly empty AttributeValue is indicative of invalid input or potential errors");
    }
}