blob: b15b409afa94d09efb73b574100a81ae6893b48e [file] [log] [blame]
Title: Apache Accumulo Constraints Example
Notice: Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
.
http://www.apache.org/licenses/LICENSE-2.0
.
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
This tutorial uses the following Java classes, which can be found in org.apache.accumulo.examples.simple.constraints in the examples-simple module:
* AlphaNumKeyConstraint.java - a constraint that requires alphanumeric keys
* NumericValueConstraint.java - a constraint that requires numeric string values
This an example of how to create a table with constraints. Below a table is
created with two example constraints. One constraints does not allow non alpha
numeric keys. The other constraint does not allow non numeric values. Two
inserts that violate these constraints are attempted and denied. The scan at
the end shows the inserts were not allowed.
$ ./bin/accumulo shell -u username -p password
Shell - Apache Accumulo Interactive Shell
-
- version: 1.5.0
- instance name: instance
- instance id: 00000000-0000-0000-0000-000000000000
-
- type 'help' for a list of available commands
-
username@instance> createtable testConstraints
username@instance testConstraints> constraint -a org.apache.accumulo.examples.simple.constraints.NumericValueConstraint
username@instance testConstraints> constraint -a org.apache.accumulo.examples.simple.constraints.AlphaNumKeyConstraint
username@instance testConstraints> insert r1 cf1 cq1 1111
username@instance testConstraints> insert r1 cf1 cq1 ABC
Constraint Failures:
ConstraintViolationSummary(constrainClass:org.apache.accumulo.examples.simple.constraints.NumericValueConstraint, violationCode:1, violationDescription:Value is not numeric, numberOfViolatingMutations:1)
username@instance testConstraints> insert r1! cf1 cq1 ABC
Constraint Failures:
ConstraintViolationSummary(constrainClass:org.apache.accumulo.examples.simple.constraints.NumericValueConstraint, violationCode:1, violationDescription:Value is not numeric, numberOfViolatingMutations:1)
ConstraintViolationSummary(constrainClass:org.apache.accumulo.examples.simple.constraints.AlphaNumKeyConstraint, violationCode:1, violationDescription:Row was not alpha numeric, numberOfViolatingMutations:1)
username@instance testConstraints> scan
r1 cf1:cq1 [] 1111
username@instance testConstraints>