public static IcebergTableName from(String name)
    {
        Matcher match = TABLE_PATTERN.matcher(name);
        if (!match.matches()) {
            throw new PrestoException(NOT_SUPPORTED, "Invalid Iceberg table name: " + name);
        }

        String table = match.group("table");
        String typeString = match.group("type");
        String version1 = match.group("ver1");
        String version2 = match.group("ver2");

        IcebergTableType type = DATA;
        if (typeString != null) {
            try {
                type = IcebergTableType.valueOf(typeString.toUpperCase(ROOT));
            }
            catch (IllegalArgumentException e) {
                throw new PrestoException(NOT_SUPPORTED, format("Invalid Iceberg table name (unknown type '%s'): %s", typeString, name));
            }
        }

        if (!type.isPublic()) {
            throw new PrestoException(NOT_SUPPORTED, format("Internal Iceberg table name (type '%s'): %s", typeString, name));
        }

        Optional<Long> version = Optional.empty();
        Optional<Long> changelogEndVersion = Optional.empty();
        if (type == DATA || type == PARTITIONS || type == MANIFESTS || type == FILES) {
            if (version1 != null && version2 != null) {
                throw new PrestoException(NOT_SUPPORTED, "Invalid Iceberg table name (cannot specify two @ versions): " + name);
            }
            if (version1 != null) {
                version = Optional.of(parseLong(version1));
            }
            else if (version2 != null) {
                version = Optional.of(parseLong(version2));
            }
        }
        else if (type == CHANGELOG) {
            version = Optional.ofNullable(version1).map(Long::parseLong);
            changelogEndVersion = Optional.ofNullable(version2).map(Long::parseLong);
        }
        else if (version1 != null || version2 != null) {
            throw new PrestoException(NOT_SUPPORTED, format("Invalid Iceberg table name (cannot use @ version with table type '%s'): %s", type, name));
        }

        return new IcebergTableName(table, type, version, changelogEndVersion);
    }
@Test
    public void testFrom()
    {
        assertFrom("abc", "abc", IcebergTableType.DATA);
        assertFrom("abc@123", "abc", IcebergTableType.DATA, Optional.of(123L));
        assertFrom("abc$data", "abc", IcebergTableType.DATA);
        assertFrom("xyz@456", "xyz", IcebergTableType.DATA, Optional.of(456L));
        assertFrom("xyz$data@456", "xyz", IcebergTableType.DATA, Optional.of(456L));
        assertFrom("abc$partitions@456", "abc", IcebergTableType.PARTITIONS, Optional.of(456L));
        assertFrom("abc$manifests@456", "abc", IcebergTableType.MANIFESTS, Optional.of(456L));
        assertFrom("abc$manifests@456", "abc", IcebergTableType.MANIFESTS, Optional.of(456L));
        assertFrom("abc$history", "abc", IcebergTableType.HISTORY);
        assertFrom("abc$snapshots", "abc", IcebergTableType.SNAPSHOTS);
        assertFrom("abc$changelog", "abc", IcebergTableType.CHANGELOG);
        assertFrom("abc@123$changelog", "abc", IcebergTableType.CHANGELOG, Optional.of(123L));
        assertFrom("abc$changelog@123", "abc", IcebergTableType.CHANGELOG, Optional.empty(), Optional.of(123L));
        assertFrom("abc@123$changelog@124", "abc", IcebergTableType.CHANGELOG, Optional.of(123L), Optional.of(124L));

        assertInvalid("abc@xyz", "Invalid Iceberg table name: abc@xyz");
        assertInvalid("abc$what", "Invalid Iceberg table name (unknown type 'what'): abc$what");
        assertInvalid("abc@123$data@456", "Invalid Iceberg table name (cannot specify two @ versions): abc@123$data@456");
        assertInvalid("abc@123$snapshots", "Invalid Iceberg table name (cannot use @ version with table type 'SNAPSHOTS'): abc@123$snapshots");
        assertInvalid("abc$snapshots@456", "Invalid Iceberg table name (cannot use @ version with table type 'SNAPSHOTS'): abc$snapshots@456");
    }