Your cart is currently empty!
Author: alien
-
Khóa học miễn phí DynamoDB – Data Types nhận dự án làm có lương
DynamoDB – Data Types
Data types supported by DynamoDB include those specific to attributes, actions, and your coding language of choice.
Attribute Data Types
DynamoDB supports a large set of data types for table attributes. Each data type falls into one of the three following categories −
-
Scalar − These types represent a single value, and include number, string, binary, Boolean, and null.
-
Document − These types represent a complex structure possessing nested attributes, and include lists and maps.
-
Set − These types represent multiple scalars, and include string sets, number sets, and binary sets.
Remember DynamoDB as a schemaless, NoSQL database that does not need attribute or data type definitions when creating a table. It only requires a primary key attribute data types in contrast to RDBMS, which require column data types on table creation.
Scalars
-
Numbers − They are limited to 38 digits, and are either positive, negative, or zero.
-
String − They are Unicode using UTF-8, with a minimum length of >0 and maximum of 400KB.
-
Binary − They store any binary data, e.g., encrypted data, images, and compressed text. DynamoDB views its bytes as unsigned.
-
Boolean − They store true or false.
-
Null − They represent an unknown or undefined state.
Document
-
List − It stores ordered value collections, and uses square ([…]) brackets.
-
Map − It stores unordered name-value pair collections, and uses curly ({…}) braces.
Set
Sets must contain elements of the same type whether number, string, or binary. The only limits placed on sets consist of the 400KB item size limit, and each element being unique.
Action Data Types
DynamoDB API holds various data types used by actions. You can review a selection of the following key types −
-
AttributeDefinition − It represents key table and index schema.
-
Capacity − It represents the quantity of throughput consumed by a table or index.
-
CreateGlobalSecondaryIndexAction − It represents a new global secondary index added to a table.
-
LocalSecondaryIndex − It represents local secondary index properties.
-
ProvisionedThroughput − It represents the provisioned throughput for an index or table.
-
PutRequest − It represents PutItem requests.
-
TableDescription − It represents table properties.
Supported Java Datatypes
DynamoDB provides support for primitive data types, Set collections, and arbitrary types for Java.
Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc
-
Khóa học miễn phí DynamoDB – Create Table nhận dự án làm có lương
DynamoDB – Create Table
Creating a table generally consists of spawning the table, naming it, establishing its primary key attributes, and setting attribute data types.
Utilize the GUI Console, Java, or another option to perform these tasks.
Create Table using the GUI Console
Create a table by accessing the console at . Then choose the “Create Table” option.

Our example generates a table populated with product information, with products of unique attributes identified by an ID number (numeric attribute). In the Create Table screen, enter the table name within the table name field; enter the primary key (ID) within the partition key field; and enter “Number” for the data type.

After entering all information, select Create.
Create Table using Java
Use Java to create the same table. Its primary key consists of the following two attributes −
-
ID − Use a partition key, and the ScalarAttributeType N, meaning number.
-
Nomenclature − Use a sort key, and the ScalarAttributeType S, meaning string.
Java uses the createTable method to generate a table; and within the call, table name, primary key attributes, and attribute data types are specified.
You can review the following example −
import java.util.Arrays; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; import com.amazonaws.services.dynamodbv2.document.DynamoDB; import com.amazonaws.services.dynamodbv2.document.Table; import com.amazonaws.services.dynamodbv2.model.AttributeDefinition; import com.amazonaws.services.dynamodbv2.model.KeySchemaElement; import com.amazonaws.services.dynamodbv2.model.KeyType; import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput; import com.amazonaws.services.dynamodbv2.model.ScalarAttributeType; public class ProductsCreateTable { public static void main(String[] args) throws Exception { AmazonDynamoDBClient client = new AmazonDynamoDBClient() .withEndpoint("http://localhost:8000"); DynamoDB dynamoDB = new DynamoDB(client); String tableName = "Products"; try { System.out.println("Creating the table, wait..."); Table table = dynamoDB.createTable (tableName, Arrays.asList ( new KeySchemaElement("ID", KeyType.HASH), // the partition key // the sort key new KeySchemaElement("Nomenclature", KeyType.RANGE) ), Arrays.asList ( new AttributeDefinition("ID", ScalarAttributeType.N), new AttributeDefinition("Nomenclature", ScalarAttributeType.S) ), new ProvisionedThroughput(10L, 10L) ); table.waitForActive(); System.out.println("Table created successfully. Status: " + table.getDescription().getTableStatus()); } catch (Exception e) { System.err.println("Cannot create the table: "); System.err.println(e.getMessage()); } } }
In the above example, note the endpoint: .withEndpoint.
It indicates the use of a local install by using the localhost. Also, note the required ProvisionedThroughput parameter, which the local install ignores.
Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc