@@ -74,65 +74,11 @@ private static Object stringToObj(DataType dataType, Object val) {
7474 case STRING :
7575 return valString ;
7676 case DATE :
77- {
78- try {
79- return Integer .valueOf (valString );
80- } catch (Exception e ) {
81- try {
82- LocalDate date = LocalDate .parse (valString , DateTimeFormatter .ISO_LOCAL_DATE );
83- long epochDays = date .toEpochDay ();
84- return Integer .valueOf ((int ) epochDays );
85- } catch (Exception e1 ) {
86- throw new InvalidArgumentException ("unable to parse date string to date. DataType ["
87- + dataType
88- + "], Object ["
89- + valString
90- + "], class ["
91- + valString .getClass ()
92- + "]" , e1 );
93- }
94- }
95- }
77+ return parseDate (valString );
9678 case TIME32 :
97- {
98- try {
99- return Integer .valueOf (valString );
100- } catch (Exception e ) {
101- try {
102- LocalTime time = LocalTime .parse (valString , DateTimeFormatter .ISO_LOCAL_TIME );
103- int seconds = time .toSecondOfDay ();
104- return Integer .valueOf (seconds );
105- } catch (Exception e1 ) {
106- throw new InvalidArgumentException ("unable to parse time32 string to int. DataType ["
107- + dataType
108- + "], Object ["
109- + valString
110- + "], class ["
111- + valString .getClass ()
112- + "]" , e1 );
113- }
114- }
115- }
79+ return parseTime32 (valString );
11680 case TIMESTAMP :
117- {
118- try {
119- return Long .valueOf (valString );
120- } catch (Exception e ) {
121- try {
122- LocalDateTime dateTime = LocalDateTime .parse (valString , DateTimeFormatter .ISO_DATE_TIME );
123- long millis = dateTime .toEpochSecond (ZoneOffset .UTC ) * 1000 ;
124- return Long .valueOf (millis );
125- } catch (Exception e1 ) {
126- throw new InvalidArgumentException ("unable to parse timestamp string to long. DataType ["
127- + dataType
128- + "], Object ["
129- + valString
130- + "], class ["
131- + valString .getClass ()
132- + "]" , e1 );
133- }
134- }
135- }
81+ return parseTimestamp (valString );
13682 default :
13783 throw new IllegalStateException ("Unexpected value: " + dataType );
13884 }
@@ -149,6 +95,65 @@ private static Object stringToObj(DataType dataType, Object val) {
14995 }
15096 }
15197
98+ private static Integer parseDate (String valString ) {
99+ try {
100+ return Integer .valueOf (valString );
101+ } catch (Exception e ) {
102+ try {
103+ LocalDate date = LocalDate .parse (valString , DateTimeFormatter .ISO_LOCAL_DATE );
104+ long epochDays = date .toEpochDay ();
105+ return (int ) epochDays ;
106+ } catch (Exception e1 ) {
107+ throw new InvalidArgumentException (
108+ "Unable to parse date string to date. Object ["
109+ + valString
110+ + "], class ["
111+ + valString .getClass ()
112+ + "]." ,
113+ e1 );
114+ }
115+ }
116+ }
117+
118+ private static Integer parseTime32 (String valString ) {
119+ try {
120+ return Integer .valueOf (valString );
121+ } catch (Exception e ) {
122+ try {
123+ LocalTime time = LocalTime .parse (valString , DateTimeFormatter .ISO_LOCAL_TIME );
124+ return time .toSecondOfDay ();
125+ } catch (Exception e1 ) {
126+ throw new InvalidArgumentException (
127+ "Unable to parse time32 string to int. Object ["
128+ + valString
129+ + "], class ["
130+ + valString .getClass ()
131+ + "]." ,
132+ e1 );
133+ }
134+ }
135+ }
136+
137+ private static Long parseTimestamp (String valString ) {
138+ try {
139+ return Long .valueOf (valString );
140+ } catch (Exception e ) {
141+ try {
142+ LocalDateTime dateTime =
143+ LocalDateTime .parse (valString , DateTimeFormatter .ISO_DATE_TIME );
144+ return dateTime .toEpochSecond (ZoneOffset .UTC ) * 1000 ;
145+ } catch (Exception e1 ) {
146+ throw new InvalidArgumentException (
147+ "Unable to parse timestamp string to long. Object ["
148+ + valString
149+ + "], class ["
150+ + valString .getClass ()
151+ + "]." ,
152+ e1 );
153+ }
154+ }
155+ }
156+
152157 public static PropertyValue parseProto (PropertyValuePb proto ) {
153158 try {
154159 DataType dataType = DataType .parseProto (proto .getDataType ());
0 commit comments