aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/parallelai/spyglass/jdbc/JDBCScheme.java
blob: 5007895153d21e5bccf781253d243ba3d8990cff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
/*
 * Copyright (c) 2009 Concurrent, Inc.
 *
 * This work has been released into the public domain
 * by the copyright holder. This applies worldwide.
 *
 * In case this is not legally possible:
 * The copyright holder grants any entity the right
 * to use this work for any purpose, without any
 * conditions, unless such conditions are required by law.
 */

package parallelai.spyglass.jdbc;

import cascading.flow.FlowProcess;
import cascading.scheme.Scheme;
import cascading.scheme.SinkCall;
import cascading.scheme.SourceCall;
import cascading.tap.Tap;
import cascading.tap.TapException;
import cascading.tuple.Fields;
import cascading.tuple.Tuple;
import cascading.tuple.TupleEntry;
import cascading.util.Util;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.RecordReader;

import parallelai.spyglass.jdbc.db.DBInputFormat;
import parallelai.spyglass.jdbc.db.DBOutputFormat;

import java.io.IOException;
import java.util.Arrays;

/**
 * Class JDBCScheme defines what its parent Tap will select and insert/update into the sql database.
 * <p/>
 * If updateBy column names are given, a SQL UPDATE statement will be generated if the values in those columns
 * for the given Tuple are all not {@code null}. Otherwise an INSERT statement will be generated.
 * <p/>
 * Some constructors take columnFields and updateByFields. These values will be used during field name resolution
 * to bind this Scheme to the source and sink branches in a give assembly. These fields 'alias' the column names
 * in the respective arrays. In other words, if your DB TABLE has different column names than your assembly exepects,
 * use the Fields arguments to bind the assembly to the table. Both Fields and array must be the same size.
 * <p/>
 * Override this class, {@link DBInputFormat}, and {@link DBOutputFormat} to specialize for a given vendor database.
 */
public class JDBCScheme extends Scheme<JobConf, RecordReader, OutputCollector, Object[], Object[]>
{
    private Class<? extends DBInputFormat> inputFormatClass;
    private Class<? extends DBOutputFormat> outputFormatClass;
    private String[] columns;
    private String[] orderBy;
    private String conditions;
    private String[] updateBy;
    private Fields updateValueFields;
    private Fields updateByFields;
    private Fields columnFields;
    private Tuple updateIfTuple;
    private String selectQuery;
    private String countQuery;
    private long limit = -1;

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param inputFormatClass  of type Class<? extends DBInputFormat>
     * @param outputFormatClass of type Class<? extends DBOutputFormat>
     * @param columns           of type String[]
     * @param orderBy           of type String[]
     * @param conditions        of type String
     * @param limit             of type long
     * @param updateBy          of type String[]
     */
    public JDBCScheme( Class<? extends DBInputFormat> inputFormatClass, Class<? extends DBOutputFormat> outputFormatClass, String[] columns, String[] orderBy, String conditions, long limit, String[] updateBy )
    {
        this( inputFormatClass, outputFormatClass, new Fields( columns ), columns, orderBy, conditions, limit, updateBy != null ? new Fields( updateBy ) : null, updateBy );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param inputFormatClass  of type Class<? extends DBInputFormat>
     * @param outputFormatClass of type Class<? extends DBOutputFormat>
     * @param columnFields      of type Fields
     * @param columns           of type String[]
     * @param orderBy           of type String[]
     * @param conditions        of type String
     * @param limit             of type long
     * @param updateByFields    of type Fields
     * @param updateBy          of type String[]
     */
    public JDBCScheme( Class<? extends DBInputFormat> inputFormatClass, Class<? extends DBOutputFormat> outputFormatClass, Fields columnFields, String[] columns, String[] orderBy, String conditions, long limit, Fields updateByFields, String[] updateBy )
    {
        this.columnFields = columnFields;

        verifyColumns( columnFields, columns );

        setSinkFields( columnFields );
        setSourceFields( columnFields );

        if( updateBy != null && updateBy.length != 0 )
        {
            this.updateBy = updateBy;
            this.updateByFields = updateByFields;

            if( updateByFields.size() != updateBy.length )
                throw new IllegalArgumentException( "updateByFields and updateBy must be the same size" );

            if( !this.columnFields.contains( this.updateByFields ) )
                throw new IllegalArgumentException( "columnFields must contain updateByFields column names" );

            this.updateValueFields = columnFields.subtract( updateByFields ).append( updateByFields );
            this.updateIfTuple = Tuple.size( updateByFields.size() ); // all nulls
        }

        this.columns = columns;
        this.orderBy = orderBy;
        this.conditions = conditions;
        this.limit = limit;

        this.inputFormatClass = inputFormatClass;
        this.outputFormatClass = outputFormatClass;
    }

    private void verifyColumns( Fields columnFields, String[] columns )
    {
        if( columnFields.size() != columns.length )
            throw new IllegalArgumentException( "columnFields and columns must be the same size" );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param inputFormatClass  of type Class<? extends DBInputFormat>
     * @param outputFormatClass of type Class<? extends DBOutputFormat>
     * @param columns           of type String[]
     * @param orderBy           of type String[]
     * @param conditions        of type String
     * @param updateBy          of type String[]
     */
    public JDBCScheme( Class<? extends DBInputFormat> inputFormatClass, Class<? extends DBOutputFormat> outputFormatClass, String[] columns, String[] orderBy, String conditions, String[] updateBy )
    {
        this( inputFormatClass, outputFormatClass, columns, orderBy, conditions, -1, updateBy );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param inputFormatClass  of type Class<? extends DBInputFormat>
     * @param outputFormatClass of type Class<? extends DBOutputFormat>
     * @param columnFields      of type Fields
     * @param columns           of type String[]
     * @param orderBy           of type String[]
     * @param conditions        of type String
     * @param updateByFields    of type Fields
     * @param updateBy          of type String[]
     */
    public JDBCScheme( Class<? extends DBInputFormat> inputFormatClass, Class<? extends DBOutputFormat> outputFormatClass, Fields columnFields, String[] columns, String[] orderBy, String conditions, Fields updateByFields, String[] updateBy )
    {
        this( inputFormatClass, outputFormatClass, columnFields, columns, orderBy, conditions, -1, updateByFields, updateBy );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param inputFormatClass  of type Class<? extends DBInputFormat>
     * @param outputFormatClass of type Class<? extends DBOutputFormat>
     * @param columns           of type String[]
     * @param orderBy           of type String[]
     * @param updateBy          of type String[]
     */
    public JDBCScheme( Class<? extends DBInputFormat> inputFormatClass, Class<? extends DBOutputFormat> outputFormatClass, String[] columns, String[] orderBy, String[] updateBy )
    {
        this( inputFormatClass, outputFormatClass, columns, orderBy, null, updateBy );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param inputFormatClass  of type Class<? extends DBInputFormat>
     * @param outputFormatClass of type Class<? extends DBOutputFormat>
     * @param columnFields      of type Fields
     * @param columns           of type String[]
     * @param orderBy           of type String[]
     * @param updateByFields    of type Fields
     * @param updateBy          of type String[]
     */
    public JDBCScheme( Class<? extends DBInputFormat> inputFormatClass, Class<? extends DBOutputFormat> outputFormatClass, Fields columnFields, String[] columns, String[] orderBy, Fields updateByFields, String[] updateBy )
    {
        this( inputFormatClass, outputFormatClass, columnFields, columns, orderBy, null, -1, updateByFields, updateBy );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columns  of type String[]
     * @param orderBy  of type String[]
     * @param updateBy of type String[]
     */
    public JDBCScheme( String[] columns, String[] orderBy, String[] updateBy )
    {
        this( null, null, columns, orderBy, updateBy );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columnFields   of type Fields
     * @param columns        of type String[]
     * @param orderBy        of type String[]
     * @param updateByFields of type Fields
     * @param updateBy       of type String[]
     */
    public JDBCScheme( Fields columnFields, String[] columns, String[] orderBy, Fields updateByFields, String[] updateBy )
    {
        this( null, null, columnFields, columns, orderBy, updateByFields, updateBy );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columns    of type String[]
     * @param orderBy    of type String[]
     * @param conditions of type String
     * @param limit      of type long
     */
    public JDBCScheme( String[] columns, String[] orderBy, String conditions, long limit )
    {
        this( null, null, columns, orderBy, conditions, limit, null );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columnFields of type Fields
     * @param columns      of type String[]
     * @param orderBy      of type String[]
     * @param conditions   of type String
     * @param limit        of type long
     */
    public JDBCScheme( Fields columnFields, String[] columns, String[] orderBy, String conditions, long limit )
    {
        this( null, null, columnFields, columns, orderBy, conditions, limit, null, null );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columns    of type String[]
     * @param orderBy    of type String[]
     * @param conditions of type String
     */
    public JDBCScheme( String[] columns, String[] orderBy, String conditions )
    {
        this( null, null, columns, orderBy, conditions, null );
    }

    public JDBCScheme( Fields columnFields, String[] columns, String[] orderBy, String conditions )
    {
        this( null, null, columnFields, columns, orderBy, conditions, null, null );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columns of type String[]
     * @param orderBy of type String[]
     * @param limit   of type long
     */
    public JDBCScheme( String[] columns, String[] orderBy, long limit )
    {
        this( null, null, columns, orderBy, null, limit, null );
    }

    public JDBCScheme( Fields columnFields, String[] columns, String[] orderBy, long limit )
    {
        this( null, null, columnFields, columns, orderBy, null, limit, null, null );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columns of type String[]
     * @param orderBy of type String[]
     */
    public JDBCScheme( String[] columns, String[] orderBy )
    {
        this( null, null, columns, orderBy, null );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columnFields of type Fields
     * @param columns      of type String[]
     * @param orderBy      of type String[]
     */
    public JDBCScheme( Fields columnFields, String[] columns, String[] orderBy )
    {
        this( null, null, columnFields, columns, orderBy, null, -1, null, null );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columns    of type String[]
     * @param conditions of type String
     * @param limit      of type long
     */
    public JDBCScheme( String[] columns, String conditions, long limit )
    {
        this( null, null, columns, null, conditions, limit, null );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columnFields of type Fields
     * @param columns      of type String[]
     * @param conditions   of type String
     * @param limit        of type long
     */
    public JDBCScheme( Fields columnFields, String[] columns, String conditions, long limit )
    {
        this( null, null, columnFields, columns, null, conditions, limit, null, null );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columns    of type String[]
     * @param conditions of type String
     */
    public JDBCScheme( String[] columns, String conditions )
    {
        this( null, null, columns, null, conditions, null );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columnFields of type Fields
     * @param columns      of type String[]
     * @param conditions   of type String
     */
    public JDBCScheme( Fields columnFields, String[] columns, String conditions )
    {
        this( null, null, columnFields, columns, null, conditions, null, null );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columns of type String[]
     * @param limit   of type long
     */
    public JDBCScheme( String[] columns, long limit )
    {
        this( null, null, columns, null, null, limit, null );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columnFields of type Fields
     * @param columns      of type String[]
     * @param limit        of type long
     */
    public JDBCScheme( Fields columnFields, String[] columns, long limit )
    {
        this( null, null, columnFields, columns, null, null, limit, null, null );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columns of type String[]
     */
    public JDBCScheme( String[] columns )
    {
        this( null, null, new Fields( columns ), columns, null, null, null );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columnFields of type Fields
     * @param columns      of type String[]
     */
    public JDBCScheme( Fields columnFields, String[] columns )
    {
        this( null, null, columnFields, columns, null, null, null );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     * <p/>
     * Use this constructor if the data source may only be used as a source.
     *
     * @param inputFormatClass of type Class<? extends DBInputFormat>
     * @param columns          of type String[]
     * @param selectQuery      of type String
     * @param countQuery       of type String
     * @param limit            of type long
     */
    public JDBCScheme( Class<? extends DBInputFormat> inputFormatClass, String[] columns, String selectQuery, String countQuery, long limit )
    {
        this( inputFormatClass, new Fields( columns ), columns, selectQuery, countQuery, limit );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param inputFormatClass of type Class<? extends DBInputFormat>
     * @param columnFields     of type Fields
     * @param columns          of type String[]
     * @param selectQuery      of type String
     * @param countQuery       of type String
     * @param limit            of type long
     */
    public JDBCScheme( Class<? extends DBInputFormat> inputFormatClass, Fields columnFields, String[] columns, String selectQuery, String countQuery, long limit )
    {
        this.columnFields = columnFields;

        verifyColumns( columnFields, columns );

        setSourceFields( columnFields );

        this.columns = columns;
        this.selectQuery = selectQuery.trim().replaceAll( ";$", "" );
        this.countQuery = countQuery.trim().replaceAll( ";$", "" );
        this.limit = limit;

        this.inputFormatClass = inputFormatClass;
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     * <p/>
     * Use this constructor if the data source may only be used as a source.
     *
     * @param columns     of type String[]
     * @param selectQuery of type String
     * @param countQuery  of type String
     * @param limit       of type long
     */
    public JDBCScheme( String[] columns, String selectQuery, String countQuery, long limit )
    {
        this( null, new Fields( columns ), columns, selectQuery, countQuery, limit );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columnFields of type Fields
     * @param columns      of type String[]
     * @param selectQuery  of type String
     * @param countQuery   of type String
     * @param limit        of type long
     */
    public JDBCScheme( Fields columnFields, String[] columns, String selectQuery, String countQuery, long limit )
    {
        this( null, columnFields, columns, selectQuery, countQuery, limit );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     * <p/>
     * Use this constructor if the data source may only be used as a source.
     *
     * @param columns     of type String[]
     * @param selectQuery of type String
     * @param countQuery  of type String
     */
    public JDBCScheme( String[] columns, String selectQuery, String countQuery )
    {
        this( null, new Fields( columns ), columns, selectQuery, countQuery, -1 );
    }

    /**
     * Constructor JDBCScheme creates a new JDBCScheme instance.
     *
     * @param columnFields of type Fields
     * @param columns      of type String[]
     * @param selectQuery  of type String
     * @param countQuery   of type String
     */
    public JDBCScheme( Fields columnFields, String[] columns, String selectQuery, String countQuery )
    {
        this( null, columnFields, columns, selectQuery, countQuery, -1 );
    }

    /**
     * Method getColumns returns the columns of this JDBCScheme object.
     *
     * @return the columns (type String[]) of this JDBCScheme object.
     */
    public String[] getColumns() {
        return columns;
    }

    /**
     * Method getOrderBy returns the orderBy of this JDBCScheme object.
     *
     * @return the orderBy (type String[]) of this JDBCScheme object.
     */
    public String[] getOrderBy() {
        return orderBy;
    }

    @Override
    public void sourceConfInit( FlowProcess<JobConf> process, Tap<JobConf, RecordReader, OutputCollector> tap,
        JobConf conf ) {
        int concurrentReads = ( (JDBCTap) tap ).concurrentReads;

        if( selectQuery != null )
            DBInputFormat.setInput( conf, TupleRecord.class, selectQuery, countQuery, limit, concurrentReads );
        else {
            String tableName = ( (JDBCTap) tap ).getTableName();
            String joinedOrderBy = orderBy != null ? Util.join( orderBy, ", " ) : null;
            DBInputFormat.setInput( conf, TupleRecord.class, tableName, conditions, joinedOrderBy, limit, concurrentReads, columns );
        }

        if( inputFormatClass != null )
            conf.setInputFormat( inputFormatClass );
    }

    @Override
    public void sinkConfInit( FlowProcess<JobConf> process, Tap<JobConf, RecordReader, OutputCollector> tap,
        JobConf conf ) {
        if( selectQuery != null )
            throw new TapException( "cannot sink to this Scheme" );

        String tableName = ( (JDBCTap) tap ).getTableName();
        int batchSize = ( (JDBCTap) tap ).getBatchSize();
        DBOutputFormat.setOutput( conf, DBOutputFormat.class, tableName, columns, updateBy, batchSize );

        if( outputFormatClass != null )
            conf.setOutputFormat( outputFormatClass );
    }

    @Override
    public void sourcePrepare( FlowProcess<JobConf> flowProcess, SourceCall<Object[], RecordReader> sourceCall )
    {
        Object[] pair = new Object[]{sourceCall.getInput().createKey(), sourceCall.getInput().createValue()};

        sourceCall.setContext( pair );
    }

    @Override
    public boolean source( FlowProcess<JobConf> flowProcess, SourceCall<Object[], RecordReader> sourceCall ) throws IOException
    {
        Object key = sourceCall.getContext()[ 0 ];
        Object value = sourceCall.getContext()[ 1 ];
        boolean result = sourceCall.getInput().next( key, value );

        if( !result )
            return false;

        Tuple newTuple = ( (TupleRecord) value ).getTuple();
        sourceCall.getIncomingEntry().setTuple( newTuple );

        return true;
    }

    @Override
    public void sourceCleanup( FlowProcess<JobConf> flowProcess, SourceCall<Object[], RecordReader> sourceCall ) {
        sourceCall.setContext( null );
    }

    @Override
    public void sink( FlowProcess<JobConf> flowProcess, SinkCall<Object[], OutputCollector> sinkCall ) throws IOException {
        // it's ok to use NULL here so the collector does not write anything
        TupleEntry tupleEntry = sinkCall.getOutgoingEntry();
        OutputCollector outputCollector = sinkCall.getOutput();
        if( updateBy != null )
        {
            Tuple allValues = tupleEntry.selectTuple( updateValueFields );
            Tuple updateValues = tupleEntry.selectTuple( updateByFields );

            allValues = cleanTuple( allValues );

            TupleRecord key = new TupleRecord( allValues );

            if( updateValues.equals( updateIfTuple ) )
                outputCollector.collect( key, null );
            else
                outputCollector.collect( key, key );

            return;
        }

        Tuple result = tupleEntry.selectTuple( getSinkFields() );

        result = cleanTuple( result );

        outputCollector.collect( new TupleRecord( result ), null );
    }

    /**
     * Provides a hook for subclasses to escape or modify any values before creating the final SQL statement.
     *
     * @param result
     * @return
     */
    protected Tuple cleanTuple( Tuple result ) {
        return result;
    }

    @Override
    public boolean equals( Object object ) {
        if( this == object )
            return true;
        if( !( object instanceof JDBCScheme ) )
            return false;
        if( !super.equals( object ) )
            return false;

        JDBCScheme that = (JDBCScheme) object;

        if( limit != that.limit )
            return false;
        if( columnFields != null ? !columnFields.equals( that.columnFields ) : that.columnFields != null )
            return false;
        if( !Arrays.equals( columns, that.columns ) )
            return false;
        if( conditions != null ? !conditions.equals( that.conditions ) : that.conditions != null )
            return false;
        if( countQuery != null ? !countQuery.equals( that.countQuery ) : that.countQuery != null )
            return false;
        if( inputFormatClass != null ? !inputFormatClass.equals( that.inputFormatClass ) : that.inputFormatClass != null )
            return false;
        if( !Arrays.equals( orderBy, that.orderBy ) )
            return false;
        if( outputFormatClass != null ? !outputFormatClass.equals( that.outputFormatClass ) : that.outputFormatClass != null )
            return false;
        if( selectQuery != null ? !selectQuery.equals( that.selectQuery ) : that.selectQuery != null )
            return false;
        if( !Arrays.equals( updateBy, that.updateBy ) )
            return false;
        if( updateByFields != null ? !updateByFields.equals( that.updateByFields ) : that.updateByFields != null )
            return false;
        if( updateIfTuple != null ? !updateIfTuple.equals( that.updateIfTuple ) : that.updateIfTuple != null )
            return false;
        if( updateValueFields != null ? !updateValueFields.equals( that.updateValueFields ) : that.updateValueFields != null )
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + ( inputFormatClass != null ? inputFormatClass.hashCode() : 0 );
        result = 31 * result + ( outputFormatClass != null ? outputFormatClass.hashCode() : 0 );
        result = 31 * result + ( columns != null ? Arrays.hashCode( columns ) : 0 );
        result = 31 * result + ( orderBy != null ? Arrays.hashCode( orderBy ) : 0 );
        result = 31 * result + ( conditions != null ? conditions.hashCode() : 0 );
        result = 31 * result + ( updateBy != null ? Arrays.hashCode( updateBy ) : 0 );
        result = 31 * result + ( updateValueFields != null ? updateValueFields.hashCode() : 0 );
        result = 31 * result + ( updateByFields != null ? updateByFields.hashCode() : 0 );
        result = 31 * result + ( columnFields != null ? columnFields.hashCode() : 0 );
        result = 31 * result + ( updateIfTuple != null ? updateIfTuple.hashCode() : 0 );
        result = 31 * result + ( selectQuery != null ? selectQuery.hashCode() : 0 );
        result = 31 * result + ( countQuery != null ? countQuery.hashCode() : 0 );
        result = 31 * result + (int) ( limit ^ ( limit >>> 32 ) );
        return result;
    }
}