|
19 | 19 |
|
20 | 20 | package org.apache.iotdb.relational.it.schema; |
21 | 21 |
|
22 | | -import org.apache.iotdb.commons.utils.WindowsOSUtils; |
23 | 22 | import org.apache.iotdb.db.it.utils.TestUtils; |
24 | 23 | import org.apache.iotdb.isession.ITableSession; |
25 | 24 | import org.apache.iotdb.it.env.EnvFactory; |
|
32 | 31 |
|
33 | 32 | import org.apache.tsfile.enums.ColumnCategory; |
34 | 33 | import org.apache.tsfile.enums.TSDataType; |
35 | | -import org.apache.tsfile.external.commons.lang3.SystemUtils; |
36 | 34 | import org.apache.tsfile.write.record.Tablet; |
37 | 35 | import org.apache.tsfile.write.schema.IMeasurementSchema; |
38 | 36 | import org.apache.tsfile.write.schema.MeasurementSchema; |
|
43 | 41 | import org.junit.experimental.categories.Category; |
44 | 42 | import org.junit.runner.RunWith; |
45 | 43 |
|
46 | | -import java.io.File; |
47 | | -import java.nio.file.Files; |
48 | | -import java.nio.file.Paths; |
49 | 44 | import java.sql.Connection; |
50 | 45 | import java.sql.ResultSet; |
51 | 46 | import java.sql.ResultSetMetaData; |
@@ -783,142 +778,6 @@ public void testConcurrentAutoCreateAndDropColumn() throws Exception { |
783 | 778 | } |
784 | 779 | } |
785 | 780 |
|
786 | | - @Test |
787 | | - public void testTableObjectCheck() throws Exception { |
788 | | - final Set<String> illegal = new HashSet<>(Arrays.asList("./", ".", "..", ".\\", "../hack")); |
789 | | - if (SystemUtils.IS_OS_WINDOWS) { |
790 | | - illegal.add("C."); |
791 | | - illegal.add("a:b<|"); |
792 | | - illegal.add("COM1"); |
793 | | - } |
794 | | - for (final String single : illegal) { |
795 | | - testObject4SingleIllegalPath(single); |
796 | | - } |
797 | | - } |
798 | | - |
799 | | - private void testObject4SingleIllegalPath(final String illegal) throws Exception { |
800 | | - try (final Connection connection = |
801 | | - EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); |
802 | | - final Statement statement = connection.createStatement(); |
803 | | - final ITableSession session = EnvFactory.getEnv().getTableSessionConnection()) { |
804 | | - statement.execute("create database if not exists db2"); |
805 | | - statement.execute("use db2"); |
806 | | - |
807 | | - // Test auto-create table |
808 | | - final String testObject = |
809 | | - System.getProperty("user.dir") |
810 | | - + File.separator |
811 | | - + "target" |
812 | | - + File.separator |
813 | | - + "test-classes" |
814 | | - + File.separator |
815 | | - + "object-example.pt"; |
816 | | - |
817 | | - final List<IMeasurementSchema> schemaList = new ArrayList<>(); |
818 | | - schemaList.add(new MeasurementSchema("a", TSDataType.STRING)); |
819 | | - schemaList.add(new MeasurementSchema("b", TSDataType.STRING)); |
820 | | - schemaList.add(new MeasurementSchema("c", TSDataType.INT32)); |
821 | | - schemaList.add(new MeasurementSchema(illegal, TSDataType.OBJECT)); |
822 | | - final List<ColumnCategory> columnTypes = |
823 | | - Arrays.asList( |
824 | | - ColumnCategory.TAG, |
825 | | - ColumnCategory.ATTRIBUTE, |
826 | | - ColumnCategory.FIELD, |
827 | | - ColumnCategory.FIELD); |
828 | | - final Tablet tablet = |
829 | | - new Tablet( |
830 | | - illegal, |
831 | | - IMeasurementSchema.getMeasurementNameList(schemaList), |
832 | | - IMeasurementSchema.getDataTypeList(schemaList), |
833 | | - columnTypes, |
834 | | - 1); |
835 | | - tablet.addTimestamp(0, System.currentTimeMillis()); |
836 | | - tablet.addValue(schemaList.get(0).getMeasurementName(), 0, "d1"); |
837 | | - tablet.addValue(schemaList.get(1).getMeasurementName(), 0, "a1"); |
838 | | - tablet.addValue(schemaList.get(2).getMeasurementName(), 0, 0); |
839 | | - tablet.addValue(0, 3, true, 0, Files.readAllBytes(Paths.get(testObject))); |
840 | | - |
841 | | - final String expectedTableError = |
842 | | - String.format( |
843 | | - "701: When there are object fields, the tableName %s shall not be '.', '..' or contain './', '.\\'." |
844 | | - + (SystemUtils.IS_OS_WINDOWS ? " " + WindowsOSUtils.OS_SEGMENT_ERROR : ""), |
845 | | - illegal.toLowerCase()); |
846 | | - final String expectedObjectError = |
847 | | - String.format( |
848 | | - "701: When there are object fields, the objectName %s shall not be '.', '..' or contain './', '.\\'." |
849 | | - + (SystemUtils.IS_OS_WINDOWS ? " " + WindowsOSUtils.OS_SEGMENT_ERROR : ""), |
850 | | - illegal.toLowerCase()); |
851 | | - |
852 | | - try { |
853 | | - session.executeNonQueryStatement("use db2"); |
854 | | - session.insert(tablet); |
855 | | - } catch (final Exception e) { |
856 | | - Assert.assertEquals(expectedTableError, e.getMessage()); |
857 | | - } |
858 | | - |
859 | | - statement.execute(String.format("create table \"%s\" ()", illegal)); |
860 | | - |
861 | | - try { |
862 | | - statement.execute(String.format("alter table \"%s\" add column a object", illegal)); |
863 | | - fail(); |
864 | | - } catch (final SQLException e) { |
865 | | - Assert.assertEquals(expectedTableError, e.getMessage()); |
866 | | - } |
867 | | - |
868 | | - // Test auto-create column |
869 | | - try { |
870 | | - session.executeNonQueryStatement("use db2"); |
871 | | - session.insert(tablet); |
872 | | - } catch (final Exception e) { |
873 | | - Assert.assertEquals(expectedTableError, e.getMessage()); |
874 | | - } |
875 | | - |
876 | | - try { |
877 | | - statement.execute(String.format("create table test (\"%s\" object)", illegal)); |
878 | | - fail(); |
879 | | - } catch (final SQLException e) { |
880 | | - Assert.assertEquals(expectedObjectError, e.getMessage()); |
881 | | - } |
882 | | - |
883 | | - statement.execute("create table test (a tag, b attribute, c int32, d object)"); |
884 | | - |
885 | | - // Cannot auto-extend illegal column |
886 | | - tablet.setTableName("test"); |
887 | | - try { |
888 | | - session.executeNonQueryStatement("use db2"); |
889 | | - session.insert(tablet); |
890 | | - } catch (final Exception e) { |
891 | | - Assert.assertEquals(expectedObjectError, e.getMessage()); |
892 | | - } |
893 | | - |
894 | | - // It's OK if you don't write object |
895 | | - statement.execute(String.format("insert into test (a, b, c) values ('%s', 1, 1)", illegal)); |
896 | | - try { |
897 | | - statement.execute( |
898 | | - String.format( |
899 | | - "insert into test (a, b, c, d) values ('%s', 1, 1, to_object(true, 0, X'aa'))", |
900 | | - illegal)); |
901 | | - fail(); |
902 | | - } catch (final SQLException e) { |
903 | | - Assert.assertEquals( |
904 | | - String.format( |
905 | | - "507: When there are object fields, the deviceId [test, %s] shall not be '.', '..' or contain './', '.\\'." |
906 | | - + (SystemUtils.IS_OS_WINDOWS ? " " + WindowsOSUtils.OS_SEGMENT_ERROR : ""), |
907 | | - illegal), |
908 | | - e.getMessage()); |
909 | | - } |
910 | | - |
911 | | - try { |
912 | | - statement.execute(String.format("alter table test add column \"%s\" object", illegal)); |
913 | | - fail(); |
914 | | - } catch (final SQLException e) { |
915 | | - Assert.assertEquals(expectedObjectError, e.getMessage()); |
916 | | - } |
917 | | - |
918 | | - statement.execute("drop database db2"); |
919 | | - } |
920 | | - } |
921 | | - |
922 | 781 | @Test |
923 | 782 | public void testTreeViewTable() throws Exception { |
924 | 783 | try (final Connection connection = EnvFactory.getEnv().getConnection(); |
|
0 commit comments