This is an automated email from the ASF dual-hosted git repository. mblow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit edf9e46988b8c1090a4f20db1ba17b6f44791309 Merge: 4a834bae32 d0c631087b Author: Ali Alsuliman <[email protected]> AuthorDate: Sat Jan 6 09:41:04 2024 -0800 Merge branch 'gerrit/trinity' into 'master' Change-Id: I31d1dd61195b4f03cc983c21e309cfd9adb02f6c .../apache/asterix/metadata/MetadataManager.java | 12 +++++ .../org/apache/asterix/metadata/MetadataNode.java | 58 ++++++++++++++++++++++ .../asterix/metadata/api/IMetadataManager.java | 16 ++++++ .../apache/asterix/metadata/api/IMetadataNode.java | 17 +++++++ .../java/org/apache/hyracks/util/JSONUtil.java | 4 ++ 5 files changed, 107 insertions(+) diff --cc asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataNode.java index 03d4bb82e1,7a6de19d9d..0eb11116d9 --- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataNode.java +++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataNode.java @@@ -20,43 -20,9 +20,44 @@@ package org.apache.asterix.metadata; import static org.apache.asterix.common.api.IIdentifierMapper.Modifier.PLURAL; +import static org.apache.asterix.common.exceptions.ErrorCode.ADAPTER_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.CANNOT_DROP_DATABASE_DEPENDENT_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.CANNOT_DROP_DATAVERSE_DEPENDENT_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.CANNOT_DROP_OBJECT_DEPENDENT_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.COMPACTION_POLICY_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.DATABASE_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.DATASET_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.DATAVERSE_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.EXTERNAL_FILE_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.FEED_CONNECTION_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.FEED_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.FEED_POLICY_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.FULL_TEXT_DEFAULT_CONFIG_CANNOT_BE_DELETED_OR_CREATED; +import static org.apache.asterix.common.exceptions.ErrorCode.FUNCTION_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.INDEX_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.LIBRARY_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.METADATA_ERROR; +import static org.apache.asterix.common.exceptions.ErrorCode.NODEGROUP_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.NODE_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.SYNONYM_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.TYPE_EXISTS; +import static org.apache.asterix.common.exceptions.ErrorCode.UNKNOWN_ADAPTER; +import static org.apache.asterix.common.exceptions.ErrorCode.UNKNOWN_DATABASE; +import static org.apache.asterix.common.exceptions.ErrorCode.UNKNOWN_DATASET_IN_DATAVERSE; +import static org.apache.asterix.common.exceptions.ErrorCode.UNKNOWN_DATAVERSE; +import static org.apache.asterix.common.exceptions.ErrorCode.UNKNOWN_EXTERNAL_FILE; +import static org.apache.asterix.common.exceptions.ErrorCode.UNKNOWN_FEED; +import static org.apache.asterix.common.exceptions.ErrorCode.UNKNOWN_FEED_CONNECTION; +import static org.apache.asterix.common.exceptions.ErrorCode.UNKNOWN_FEED_POLICY; +import static org.apache.asterix.common.exceptions.ErrorCode.UNKNOWN_FUNCTION; +import static org.apache.asterix.common.exceptions.ErrorCode.UNKNOWN_INDEX; +import static org.apache.asterix.common.exceptions.ErrorCode.UNKNOWN_LIBRARY; +import static org.apache.asterix.common.exceptions.ErrorCode.UNKNOWN_NODEGROUP; +import static org.apache.asterix.common.exceptions.ErrorCode.UNKNOWN_SYNONYM; +import static org.apache.asterix.common.exceptions.ErrorCode.UNKNOWN_TYPE; import static org.apache.asterix.common.utils.IdentifierUtil.dataset; + import java.io.PrintStream; import java.rmi.RemoteException; import java.util.ArrayList; import java.util.Arrays; @@@ -162,12 -120,15 +164,15 @@@ import org.apache.asterix.transaction.m import org.apache.asterix.transaction.management.opcallbacks.UpsertOperationCallback; import org.apache.asterix.transaction.management.service.transaction.DatasetIdFactory; import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; -import org.apache.hyracks.algebricks.common.utils.Triple; + import org.apache.hyracks.algebricks.data.IPrinter; + import org.apache.hyracks.algebricks.data.IPrinterFactory; import org.apache.hyracks.api.dataflow.value.IBinaryComparator; import org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory; import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer; import org.apache.hyracks.api.exceptions.ErrorCode; import org.apache.hyracks.api.exceptions.HyracksDataException; +import org.apache.hyracks.api.util.HyracksConstants; + import org.apache.hyracks.data.std.util.ByteArrayAccessibleOutputStream; import org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder; import org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference; import org.apache.hyracks.dataflow.common.data.accessors.ITupleReference; @@@ -375,9 -332,19 +383,19 @@@ public class MetadataNode implements IM throws AlgebricksException { ExtensionMetadataDataset<T> index = getExtensionMetadataDataset(searchKey.getDatasetId()); IMetadataEntityTupleTranslator<T> tupleTranslator = index.getTupleTranslator(false); - return getEntities(txnId, searchKey.getSearchKey(), tupleTranslator, index); + return getEntities(txnId, searchKey.getSearchKey(mdIndexesProvider), tupleTranslator, index); } + @Override + public JsonNode getEntitiesAsJson(TxnId txnId, IMetadataIndex metadataIndex, int payloadPosition) + throws AlgebricksException, RemoteException { + try { + return getJsonNodes(txnId, metadataIndex, payloadPosition); + } catch (HyracksDataException e) { + throw new AlgebricksException(e); + } + } + private <T extends IExtensionMetadataEntity> ExtensionMetadataDataset<T> getExtensionMetadataDataset( ExtensionMetadataDatasetId datasetId) throws AlgebricksException { ExtensionMetadataDataset<T> index = (ExtensionMetadataDataset<T>) extensionDatasets.get(datasetId); @@@ -3051,12 -2504,43 +3069,52 @@@ return txnIdFactory; } + private Database defaultDatabase(String databaseName) { + //TODO(DB): review + if (MetadataConstants.SYSTEM_DATABASE.equals(databaseName)) { + return MetadataBuiltinEntities.SYSTEM_DATABASE; + } else { + return MetadataBuiltinEntities.DEFAULT_DATABASE; + } + } ++ + private ArrayNode getJsonNodes(TxnId txnId, IMetadataIndex mdIndex, int payloadPosition) + throws AlgebricksException, HyracksDataException { + IValueExtractor<JsonNode> valueExtractor = createValueExtractor(mdIndex, payloadPosition); + List<JsonNode> results = new ArrayList<>(); + searchIndex(txnId, mdIndex, null, valueExtractor, results); + ArrayNode array = JSONUtil.createArray(); + results.forEach(array::add); + return array; + } + + private static IValueExtractor<JsonNode> createValueExtractor(IMetadataIndex mdIndex, int payloadFieldIndex) { + return new IValueExtractor<>() { + + final ARecordType payloadRecordType = mdIndex.getPayloadRecordType(); + final IPrinterFactory printerFactory = + CleanJSONPrinterFactoryProvider.INSTANCE.getPrinterFactory(payloadRecordType); + final IPrinter printer = printerFactory.createPrinter(); + final ByteArrayAccessibleOutputStream outputStream = new ByteArrayAccessibleOutputStream(); + final PrintStream printStream = new PrintStream(outputStream); + + @Override + public JsonNode getValue(TxnId txnId, ITupleReference tuple) { + try { + byte[] serRecord = tuple.getFieldData(payloadFieldIndex); + int recordStartOffset = tuple.getFieldStart(payloadFieldIndex); + int recordLength = tuple.getFieldLength(payloadFieldIndex); + + printer.init(); + outputStream.reset(); + + printer.print(serRecord, recordStartOffset, recordLength, printStream); + printStream.flush(); + return JSONUtil.readTree(outputStream.getByteArray(), 0, outputStream.getLength()); + } catch (Throwable th) { + return JSONUtil.createObject(); + } + } + }; + } } diff --cc asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/api/IMetadataNode.java index 0d753d8978,378cf47ed1..ee4a2c91f9 --- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/api/IMetadataNode.java +++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/api/IMetadataNode.java @@@ -990,14 -971,29 +992,29 @@@ public interface IMetadataNode extends <T extends IExtensionMetadataEntity> List<T> getEntities(TxnId txnId, IExtensionMetadataSearchKey searchKey) throws AlgebricksException, RemoteException; + /** + * Gets all the records of a metadata dataset as JSON. + * + * @param txnId transaction id + * @param metadataIndex the metadata dataset + * @param payloadPosition the position of the record in the tuple + * + * @return the metadata records as JSON + * + * @throws AlgebricksException AlgebricksException + * @throws RemoteException RemoteException + */ + JsonNode getEntitiesAsJson(TxnId txnId, IMetadataIndex metadataIndex, int payloadPosition) + throws AlgebricksException, RemoteException; + void addFeedConnection(TxnId txnId, FeedConnection feedConnection) throws AlgebricksException, RemoteException; - FeedConnection getFeedConnection(TxnId txnId, DataverseName dataverseName, String feedName, String datasetName) - throws AlgebricksException, RemoteException; + FeedConnection getFeedConnection(TxnId txnId, String database, DataverseName dataverseName, String feedName, + String datasetName) throws AlgebricksException, RemoteException; - void dropFeedConnection(TxnId txnId, DataverseName dataverseName, String feedName, String datasetName) - throws AlgebricksException, RemoteException; + void dropFeedConnection(TxnId txnId, String database, DataverseName dataverseName, String feedName, + String datasetName) throws AlgebricksException, RemoteException; - List<FeedConnection> getFeedConnections(TxnId txnId, DataverseName dataverseName, String feedName) + List<FeedConnection> getFeedConnections(TxnId txnId, String database, DataverseName dataverseName, String feedName) throws AlgebricksException, RemoteException; }
