|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.iotdb.confignode.procedure.impl.schema; |
| 21 | + |
| 22 | +import org.apache.iotdb.commons.exception.IllegalPathException; |
| 23 | +import org.apache.iotdb.commons.path.MeasurementPath; |
| 24 | +import org.apache.iotdb.commons.path.PartialPath; |
| 25 | +import org.apache.iotdb.commons.schema.template.Template; |
| 26 | +import org.apache.iotdb.commons.schema.tree.AlterTimeSeriesOperationType; |
| 27 | +import org.apache.iotdb.confignode.procedure.store.ProcedureType; |
| 28 | +import org.apache.iotdb.db.queryengine.common.schematree.ClusterSchemaTree; |
| 29 | +import org.apache.iotdb.db.queryengine.plan.relational.metadata.fetcher.cache.TreeDeviceSchemaCacheManager; |
| 30 | +import org.apache.iotdb.db.schemaengine.template.ClusterTemplateManager; |
| 31 | + |
| 32 | +import org.apache.tsfile.enums.TSDataType; |
| 33 | +import org.apache.tsfile.file.metadata.enums.CompressionType; |
| 34 | +import org.apache.tsfile.file.metadata.enums.TSEncoding; |
| 35 | +import org.junit.Assert; |
| 36 | +import org.junit.Test; |
| 37 | + |
| 38 | +import java.io.ByteArrayOutputStream; |
| 39 | +import java.io.DataOutputStream; |
| 40 | +import java.io.IOException; |
| 41 | +import java.nio.ByteBuffer; |
| 42 | +import java.util.Arrays; |
| 43 | +import java.util.Collections; |
| 44 | +import java.util.List; |
| 45 | + |
| 46 | +public class AlterTimeSeriesDataTypeProcedureTest { |
| 47 | + |
| 48 | + @Test |
| 49 | + public void serializeDeserializeTest() throws IllegalPathException, IOException { |
| 50 | + String queryId = "1"; |
| 51 | + |
| 52 | + MeasurementPath measurementPath = getMeasurementPath(); |
| 53 | + AlterTimeSeriesDataTypeProcedure alterTimeSeriesDataTypeProcedure = |
| 54 | + new AlterTimeSeriesDataTypeProcedure( |
| 55 | + queryId, |
| 56 | + measurementPath, |
| 57 | + AlterTimeSeriesOperationType.ALTER_DATA_TYPE.getTypeValue(), |
| 58 | + TSDataType.FLOAT, |
| 59 | + false); |
| 60 | + |
| 61 | + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| 62 | + DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); |
| 63 | + alterTimeSeriesDataTypeProcedure.serialize(dataOutputStream); |
| 64 | + |
| 65 | + ByteBuffer byteBuffer = ByteBuffer.wrap(byteArrayOutputStream.toByteArray()); |
| 66 | + |
| 67 | + Assert.assertEquals( |
| 68 | + ProcedureType.ALTER_TIMESERIES_DATATYPE_PROCEDURE.getTypeCode(), byteBuffer.getShort()); |
| 69 | + |
| 70 | + AlterTimeSeriesDataTypeProcedure deserializedProcedure = |
| 71 | + new AlterTimeSeriesDataTypeProcedure(false); |
| 72 | + deserializedProcedure.deserialize(byteBuffer); |
| 73 | + |
| 74 | + Assert.assertEquals(queryId, deserializedProcedure.getQueryId()); |
| 75 | + Assert.assertEquals("root.sg1.d1.s1", deserializedProcedure.getmeasurementPath().getFullPath()); |
| 76 | + } |
| 77 | + |
| 78 | + private static MeasurementPath getMeasurementPath() throws IllegalPathException { |
| 79 | + final ClusterSchemaTree clusterSchemaTree = new ClusterSchemaTree(); |
| 80 | + final Template template1 = |
| 81 | + new Template( |
| 82 | + "t1", |
| 83 | + Arrays.asList("s1", "s2"), |
| 84 | + Arrays.asList(TSDataType.DOUBLE, TSDataType.INT32), |
| 85 | + Arrays.asList(TSEncoding.RLE, TSEncoding.RLE), |
| 86 | + Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY)); |
| 87 | + template1.setId(1); |
| 88 | + final Template template2 = |
| 89 | + new Template( |
| 90 | + "t2", |
| 91 | + Arrays.asList("t1", "t2", "t3"), |
| 92 | + Arrays.asList(TSDataType.DOUBLE, TSDataType.INT32, TSDataType.INT64), |
| 93 | + Arrays.asList(TSEncoding.RLE, TSEncoding.RLE, TSEncoding.RLBE), |
| 94 | + Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY, CompressionType.SNAPPY)); |
| 95 | + template2.setId(2); |
| 96 | + ClusterTemplateManager.getInstance().putTemplate(template1); |
| 97 | + ClusterTemplateManager.getInstance().putTemplate(template2); |
| 98 | + clusterSchemaTree.appendTemplateDevice(new PartialPath("root.sg1.d1"), false, 1, template1); |
| 99 | + clusterSchemaTree.appendTemplateDevice(new PartialPath("root.sg1.d2"), false, 2, template2); |
| 100 | + clusterSchemaTree.setDatabases(Collections.singleton("root.sg1")); |
| 101 | + clusterSchemaTree.appendSingleMeasurementPath( |
| 102 | + new MeasurementPath("root.sg1.d3.s1", TSDataType.FLOAT)); |
| 103 | + |
| 104 | + TreeDeviceSchemaCacheManager treeDeviceSchemaCacheManager = |
| 105 | + TreeDeviceSchemaCacheManager.getInstance(); |
| 106 | + treeDeviceSchemaCacheManager.put(clusterSchemaTree); |
| 107 | + final ClusterSchemaTree d1Tree = |
| 108 | + treeDeviceSchemaCacheManager.getMatchedTemplateSchema(new PartialPath("root.sg1.d1")); |
| 109 | + |
| 110 | + final String[] ALL_RESULT_NODES = new String[] {"root", "sg1", "**"}; |
| 111 | + final PartialPath ALL_MATCH_PATTERN = new PartialPath(ALL_RESULT_NODES); |
| 112 | + List<MeasurementPath> measurementPaths = d1Tree.searchMeasurementPaths(ALL_MATCH_PATTERN).left; |
| 113 | + return measurementPaths.get(0); |
| 114 | + } |
| 115 | +} |
0 commit comments