MCPcopy Create free account
hub / github.com/documentdb/documentdb / ParseNamespaceName

Function ParseNamespaceName

pg_documentdb/src/sharding/sharding.c:1883–1910  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1881
1882
1883void
1884ParseNamespaceName(const char *namespacePath, char **databaseName, char **collectionName)
1885{
1886 StringView strView = CreateStringViewFromString(namespacePath);
1887 StringView databaseView = StringViewFindPrefix(&strView, '.');
1888 if (databaseView.length == 0)
1889 {
1890 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
1891 errmsg("name needs to be fully qualified <db>.<collection>")));
1892 }
1893
1894 if (strView.length < databaseView.length + 2)
1895 {
1896 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
1897 errmsg("name needs to be fully qualified <db>.<collection>")));
1898 }
1899
1900 StringView collectionView = StringViewSubstring(&strView, databaseView.length + 1);
1901
1902 ValidateDatabaseCollection(
1903 PointerGetDatum(cstring_to_text_with_len(databaseView.string,
1904 databaseView.length)),
1905 PointerGetDatum(cstring_to_text_with_len(collectionView.string,
1906 collectionView.length)));
1907
1908 *databaseName = pnstrdup(databaseView.string, databaseView.length);
1909 *collectionName = pnstrdup(collectionView.string, collectionView.length);
1910}
1911
1912
1913static void

Calls 4

StringViewFindPrefixFunction · 0.85
StringViewSubstringFunction · 0.85

Tested by

no test coverage detected