Skip to content
Permalink
Browse files
[NO ISSUE][MD] Limit metadata identifiers to 255 bytes
- user model changes: no
- storage format changes: no
- interface changes: no

Details:

- Ensure the length of metadata identifiers doesn't exceed
  255 bytes.

Change-Id: Icf92ad741d166f35d8f132ed4ba94d35a2d1aee1
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/10304
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
Reviewed-by: Michael Blow <mblow@apache.org>
Contrib: Murtadha Hubail <mhubail@apache.org>
  • Loading branch information
mhubail committed Mar 3, 2021
1 parent 0820015 commit ce0141ac79fee0d9684b6aaee5fd3be8b90c066a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
@@ -83,23 +83,23 @@ public void testDataverseNameLimits() throws Exception {
Arrays.asList(
// #1. max single-part name
DataverseName.createSinglePartName(
StringUtils.repeat('a', MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8)),
StringUtils.repeat('a', MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8)),
// #2. max single-part name (2-byte characters)
DataverseName.createSinglePartName(
StringUtils.repeat(auml, MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8 / 2)),
StringUtils.repeat(auml, MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8 / 2)),
// #3. 4 max parts
DataverseName.create(Arrays.asList(
StringUtils.repeat('a', MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8),
StringUtils.repeat('b', MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8),
StringUtils.repeat('c', MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8),
StringUtils.repeat('d', MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8))),
StringUtils.repeat('a', MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8),
StringUtils.repeat('b', MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8),
StringUtils.repeat('c', MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8),
StringUtils.repeat('d', MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8))),
// #3. 4 max parts (2-byte characters)
DataverseName.create(Arrays.asList(
StringUtils.repeat(auml, MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8 / 2),
StringUtils.repeat(euml, MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8 / 2),
StringUtils.repeat(auml, MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8 / 2),
StringUtils.repeat(auml, MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8 / 2),
StringUtils.repeat(euml, MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8 / 2),
StringUtils.repeat(auml, MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8 / 2),
StringUtils.repeat(euml,
MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8 / 2))));
MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8 / 2))));

for (DataverseName dvNameOk : dvNameOkList) {
String sql = String.format("create dataverse %s;", dvNameOk);
@@ -114,31 +114,32 @@ public void testDataverseNameLimits() throws Exception {
Arrays.asList(
// #1. single-part name exceeds part length limit
DataverseName.createSinglePartName(
StringUtils.repeat('A', MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8 + 1)),
StringUtils.repeat('A', MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8 + 1)),
// #2 single-part name exceeds part length limit (2-byte characters)
DataverseName.createSinglePartName(StringUtils.repeat(iuml,
MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8 / 2 + 1)),
MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8 / 2 + 1)),
// #3. 2-part name, 2nd part exceed part length limit
DataverseName.create(Arrays.asList("A",
StringUtils.repeat('B', MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8 + 1))),
StringUtils.repeat('B', MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8 + 1))),
// #4. 2-part name, 2nd part exceed part length limit (2-byte characters)
DataverseName.create(Arrays.asList("A",
StringUtils.repeat(ouml,
MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8 / 2 + 1))),
MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8 / 2 + 1))),
// #5. 5-part name, each part at the part length limit, total length limit is exceeded
DataverseName.create(Arrays.asList(
StringUtils.repeat('A', MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8),
StringUtils.repeat('B', MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8),
StringUtils.repeat('C', MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8),
StringUtils.repeat('D', MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8),
StringUtils.repeat('E', MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8))),
StringUtils.repeat('A', MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8),
StringUtils.repeat('B', MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8),
StringUtils.repeat('C', MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8),
StringUtils.repeat('D', MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8),
StringUtils.repeat('E', MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8))),
// #6. 5-part name, each part at the part length limit, total length limit is exceeded (2-byte characters)
DataverseName.create(Arrays.asList(
StringUtils.repeat(iuml, MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8 / 2),
StringUtils.repeat(ouml, MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8 / 2),
StringUtils.repeat(iuml, MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8 / 2),
StringUtils.repeat(ouml, MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8 / 2),
StringUtils.repeat(iuml, MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8 / 2))),
StringUtils.repeat(iuml, MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8 / 2),
StringUtils.repeat(ouml, MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8 / 2),
StringUtils.repeat(iuml, MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8 / 2),
StringUtils.repeat(ouml, MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8 / 2),
StringUtils.repeat(iuml,
MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8 / 2))),
// #7. Multi-part name, each part at the part length limit, total length limit is exceeded
DataverseName.create(
Collections.nCopies(MetadataConstants.DATAVERSE_NAME_TOTAL_LENGTH_LIMIT_UTF8 + 1, "A")),
@@ -1749,11 +1749,7 @@ public void validateDataverseName(DataverseName dataverseName, SourceLocation so
int totalLengthUTF8 = 0;
for (String dvNamePart : dataverseName.getParts()) {
validateDatabaseObjectNameImpl(dvNamePart, sourceLoc);
int lengthUTF8 = dvNamePart.getBytes(StandardCharsets.UTF_8).length;
if (lengthUTF8 > MetadataConstants.DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8) {
throw new AsterixException(ErrorCode.INVALID_DATABASE_OBJECT_NAME, sourceLoc, dvNamePart);
}
totalLengthUTF8 += lengthUTF8;
totalLengthUTF8 += dvNamePart.getBytes(StandardCharsets.UTF_8).length;
}
if (totalLengthUTF8 > MetadataConstants.DATAVERSE_NAME_TOTAL_LENGTH_LIMIT_UTF8) {
throw new AsterixException(ErrorCode.INVALID_DATABASE_OBJECT_NAME, sourceLoc, dataverseName.toString());
@@ -1775,5 +1771,9 @@ private void validateDatabaseObjectNameImpl(String name, SourceLocation sourceLo
if (Character.isWhitespace(name.codePointAt(0))) {
throw new AsterixException(ErrorCode.INVALID_DATABASE_OBJECT_NAME, sourceLoc, name);
}
int lengthUTF8 = name.getBytes(StandardCharsets.UTF_8).length;
if (lengthUTF8 > MetadataConstants.METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8) {
throw new AsterixException(ErrorCode.INVALID_DATABASE_OBJECT_NAME, sourceLoc, name);
}
}
}
@@ -26,7 +26,7 @@
*/
public class MetadataConstants {

public static final int DATAVERSE_NAME_PART_LENGTH_LIMIT_UTF8 = 255;
public static final int METADATA_OBJECT_NAME_LENGTH_LIMIT_UTF8 = 255;
public static final int DATAVERSE_NAME_TOTAL_LENGTH_LIMIT_UTF8 = 1023;

// Name of the dataverse the metadata lives in.

0 comments on commit ce0141a

Please sign in to comment.